Commit | Line | Data |
---|---|---|
ca4e7e14 JI |
1 | /* Tcl/Tk command definitions for gdbtk. |
2 | Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. | |
3 | ||
4 | Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support. | |
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, Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include "symtab.h" | |
24 | #include "inferior.h" | |
25 | #include "command.h" | |
26 | #include "bfd.h" | |
27 | #include "symfile.h" | |
28 | #include "objfiles.h" | |
29 | #include "target.h" | |
30 | #include "gdbcore.h" | |
31 | #include "tracepoint.h" | |
32 | #include "demangle.h" | |
33 | ||
34 | #ifdef _WIN32 | |
35 | #include <winuser.h> | |
36 | #endif | |
37 | ||
38 | #include <sys/stat.h> | |
39 | ||
40 | #include <tcl.h> | |
41 | #include <tk.h> | |
42 | #include <itcl.h> | |
43 | #include <tix.h> | |
44 | #include "guitcl.h" | |
45 | #include "gdbtk.h" | |
46 | ||
47 | #ifdef IDE | |
48 | /* start-sanitize-ide */ | |
49 | #include "event.h" | |
50 | #include "idetcl.h" | |
51 | #include "ilutk.h" | |
52 | /* end-sanitize-ide */ | |
53 | #endif | |
54 | ||
55 | #ifdef ANSI_PROTOTYPES | |
56 | #include <stdarg.h> | |
57 | #else | |
58 | #include <varargs.h> | |
59 | #endif | |
60 | #include <signal.h> | |
61 | #include <fcntl.h> | |
62 | #include <unistd.h> | |
63 | #include <setjmp.h> | |
64 | #include "top.h" | |
65 | #include <sys/ioctl.h> | |
66 | #include "gdb_string.h" | |
67 | #include "dis-asm.h" | |
68 | #include <stdio.h> | |
69 | #include "gdbcmd.h" | |
70 | ||
71 | #include "annotate.h" | |
72 | #include <sys/time.h> | |
73 | ||
74 | /* This structure filled in call_wrapper and passed to | |
75 | the wrapped call function. | |
76 | It stores the command pointer and arguments | |
77 | run in the wrapper function. */ | |
78 | ||
79 | struct wrapped_call_args | |
80 | { | |
81 | Tcl_Interp *interp; | |
82 | Tcl_ObjCmdProc *func; | |
83 | int objc; | |
84 | Tcl_Obj *CONST *objv; | |
85 | int val; | |
86 | }; | |
87 | ||
88 | /* These two objects hold boolean true and false, | |
89 | and are shared by all the list objects that gdb_listfuncs | |
90 | returns. */ | |
91 | ||
92 | static Tcl_Obj *mangled, *not_mangled; | |
93 | ||
94 | /* These two control how the GUI behaves when gdb is either tracing or loading. | |
95 | They are used in this file & gdbtk_hooks.c */ | |
96 | ||
97 | int No_Update = 0; | |
98 | int load_in_progress = 0; | |
99 | ||
100 | /* | |
101 | * This is used in the register fetching routines | |
102 | */ | |
103 | ||
104 | #ifndef REGISTER_CONVERTIBLE | |
105 | #define REGISTER_CONVERTIBLE(x) (0 != 0) | |
106 | #endif | |
107 | ||
108 | #ifndef REGISTER_CONVERT_TO_VIRTUAL | |
109 | #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a) | |
110 | #endif | |
111 | ||
112 | #ifndef INVALID_FLOAT | |
113 | #define INVALID_FLOAT(x, y) (0 != 0) | |
114 | #endif | |
115 | ||
116 | ||
117 | ||
118 | /* This Structure is used in gdb_disassemble. | |
119 | We need a different sort of line table from the normal one cuz we can't | |
120 | depend upon implicit line-end pc's for lines to do the | |
121 | reordering in this function. */ | |
122 | ||
123 | struct my_line_entry { | |
124 | int line; | |
125 | CORE_ADDR start_pc; | |
126 | CORE_ADDR end_pc; | |
127 | }; | |
128 | ||
129 | /* This contains the previous values of the registers, since the last call to | |
130 | gdb_changed_register_list. */ | |
131 | ||
132 | static char old_regs[REGISTER_BYTES]; | |
133 | ||
134 | /* | |
135 | * These are routines we need from breakpoint.c. | |
136 | * at some point make these static in breakpoint.c and move GUI code there | |
137 | */ | |
138 | ||
139 | extern struct breakpoint *set_raw_breakpoint (struct symtab_and_line sal); | |
140 | extern void set_breakpoint_count (int); | |
141 | extern int breakpoint_count; | |
142 | ||
143 | ||
144 | /* | |
145 | * Declarations for routines used only in this file. | |
146 | */ | |
147 | ||
148 | int Gdbtk_Init (Tcl_Interp *interp); | |
149 | static int compare_lines PARAMS ((const PTR, const PTR)); | |
150 | static int comp_files PARAMS ((const void *, const void *)); | |
151 | static int call_wrapper PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
152 | static int gdb_actions_command PARAMS ((ClientData, Tcl_Interp *, int, | |
153 | Tcl_Obj *CONST objv[])); | |
154 | static int gdb_changed_register_list PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
155 | static int gdb_clear_file PARAMS ((ClientData, Tcl_Interp *interp, int, Tcl_Obj *CONST [])); | |
156 | static int gdb_cmd PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
157 | static int gdb_confirm_quit PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
158 | static int gdb_disassemble PARAMS ((ClientData, Tcl_Interp *, int, | |
159 | Tcl_Obj *CONST [])); | |
160 | static int gdb_eval PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
161 | static int gdb_fetch_registers PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
162 | static int gdb_find_file_command PARAMS ((ClientData, Tcl_Interp *, int, | |
163 | Tcl_Obj *CONST objv[])); | |
164 | static int gdb_force_quit PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
165 | static struct symtab *full_lookup_symtab PARAMS ((char *file)); | |
166 | static int gdb_get_args_command PARAMS ((ClientData, Tcl_Interp *, int, | |
167 | Tcl_Obj *CONST objv[])); | |
168 | static int gdb_get_breakpoint_info PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
169 | static int gdb_get_breakpoint_list PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
170 | static int gdb_get_file_command PARAMS ((ClientData, Tcl_Interp *, int, | |
171 | Tcl_Obj *CONST objv[])); | |
172 | static int gdb_get_function_command PARAMS ((ClientData, Tcl_Interp *, int, | |
173 | Tcl_Obj *CONST objv[])); | |
174 | static int gdb_get_line_command PARAMS ((ClientData, Tcl_Interp *, int, | |
175 | Tcl_Obj *CONST objv[])); | |
176 | static int gdb_get_locals_command PARAMS ((ClientData, Tcl_Interp *, int, | |
177 | Tcl_Obj *CONST objv[])); | |
178 | static int gdb_get_mem PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
179 | static int gdb_get_trace_frame_num PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); | |
180 | static int gdb_get_tracepoint_list PARAMS ((ClientData, Tcl_Interp *, int, | |
181 | Tcl_Obj *CONST objv[])); | |
182 | static int gdb_get_vars_command PARAMS ((ClientData, Tcl_Interp *, int, | |
183 | Tcl_Obj *CONST objv[])); | |
184 | static int gdb_immediate_command PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
185 | static int gdb_listfiles PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
186 | static int gdb_listfuncs PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
187 | static int gdb_loadfile PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); | |
188 | static int gdb_load_info PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); | |
189 | static int gdb_loc PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
190 | static int gdb_path_conv PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
191 | static int gdb_prompt_command PARAMS ((ClientData, Tcl_Interp *, int, | |
192 | Tcl_Obj *CONST objv[])); | |
193 | static int gdb_regnames PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
194 | static int gdb_search PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST | |
195 | objv[])); | |
196 | static int gdb_set_bp PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST objv[])); | |
197 | static int gdb_stop PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
198 | static int gdb_target_has_execution_command PARAMS ((ClientData, Tcl_Interp *, | |
199 | int, | |
200 | Tcl_Obj *CONST [])); | |
201 | static int gdb_trace_status PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
202 | static int gdb_tracepoint_exists_command PARAMS ((ClientData, Tcl_Interp *, | |
203 | int, | |
204 | Tcl_Obj *CONST objv[])); | |
205 | static int gdb_get_tracepoint_info PARAMS ((ClientData, Tcl_Interp *, int, | |
206 | Tcl_Obj *CONST objv[])); | |
207 | static void gdbtk_create_breakpoint PARAMS ((struct breakpoint *)); | |
208 | static int gdbtk_dis_asm_read_memory PARAMS ((bfd_vma, bfd_byte *, int, disassemble_info *)); | |
209 | static void gdbtk_create_tracepoint PARAMS ((struct tracepoint *)); | |
210 | static void gdbtk_delete_breakpoint PARAMS ((struct breakpoint *)); | |
211 | static void gdbtk_delete_tracepoint PARAMS ((struct tracepoint *)); | |
212 | static void gdbtk_modify_breakpoint PARAMS ((struct breakpoint *)); | |
213 | static void gdbtk_modify_tracepoint PARAMS ((struct tracepoint *)); | |
214 | static void gdbtk_print_frame_info PARAMS ((struct symtab *, int, int, int)); | |
215 | static void gdbtk_readline_end PARAMS ((void)); | |
216 | static int get_pc_register PARAMS ((ClientData, Tcl_Interp *, int, Tcl_Obj *CONST [])); | |
217 | char * get_prompt PARAMS ((void)); | |
218 | static void get_register PARAMS ((int, void *)); | |
219 | static void get_register_name PARAMS ((int, void *)); | |
220 | static int map_arg_registers PARAMS ((int, Tcl_Obj *CONST [], void (*) (int, void *), void *)); | |
221 | static void pc_changed PARAMS ((void)); | |
222 | static int perror_with_name_wrapper PARAMS ((char *args)); | |
223 | static void register_changed_p PARAMS ((int, void *)); | |
224 | void TclDebug PARAMS ((const char *fmt, ...)); | |
225 | static int wrapped_call (char *opaque_args); | |
226 | \f | |
227 | /* Gdbtk_Init | |
228 | * This loads all the Tcl commands into the Tcl interpreter. | |
229 | * | |
230 | * Arguments: | |
231 | * interp - The interpreter into which to load the commands. | |
232 | * | |
233 | * Result: | |
234 | * A standard Tcl result. | |
235 | */ | |
236 | ||
237 | int | |
238 | Gdbtk_Init (interp) | |
239 | Tcl_Interp *interp; | |
240 | { | |
241 | Tcl_CreateObjCommand (interp, "gdb_cmd", call_wrapper, gdb_cmd, NULL); | |
242 | Tcl_CreateObjCommand (interp, "gdb_immediate", call_wrapper, | |
243 | gdb_immediate_command, NULL); | |
244 | Tcl_CreateObjCommand (interp, "gdb_loc", call_wrapper, gdb_loc, NULL); | |
245 | Tcl_CreateObjCommand (interp, "gdb_path_conv", call_wrapper, gdb_path_conv, NULL); | |
246 | Tcl_CreateObjCommand (interp, "gdb_listfiles", call_wrapper, gdb_listfiles, NULL); | |
247 | Tcl_CreateObjCommand (interp, "gdb_listfuncs", call_wrapper, gdb_listfuncs, | |
248 | NULL); | |
249 | Tcl_CreateObjCommand (interp, "gdb_get_mem", call_wrapper, gdb_get_mem, | |
250 | NULL); | |
251 | Tcl_CreateObjCommand (interp, "gdb_stop", call_wrapper, gdb_stop, NULL); | |
252 | Tcl_CreateObjCommand (interp, "gdb_regnames", call_wrapper, gdb_regnames, NULL); | |
253 | Tcl_CreateObjCommand (interp, "gdb_fetch_registers", call_wrapper, | |
254 | gdb_fetch_registers, NULL); | |
255 | Tcl_CreateObjCommand (interp, "gdb_changed_register_list", call_wrapper, | |
256 | gdb_changed_register_list, NULL); | |
257 | Tcl_CreateObjCommand (interp, "gdb_disassemble", call_wrapper, | |
258 | gdb_disassemble, NULL); | |
259 | Tcl_CreateObjCommand (interp, "gdb_eval", call_wrapper, gdb_eval, NULL); | |
260 | Tcl_CreateObjCommand (interp, "gdb_get_breakpoint_list", call_wrapper, | |
261 | gdb_get_breakpoint_list, NULL); | |
262 | Tcl_CreateObjCommand (interp, "gdb_get_breakpoint_info", call_wrapper, | |
263 | gdb_get_breakpoint_info, NULL); | |
264 | Tcl_CreateObjCommand (interp, "gdb_clear_file", call_wrapper, | |
265 | gdb_clear_file, NULL); | |
266 | Tcl_CreateObjCommand (interp, "gdb_confirm_quit", call_wrapper, | |
267 | gdb_confirm_quit, NULL); | |
268 | Tcl_CreateObjCommand (interp, "gdb_force_quit", call_wrapper, | |
269 | gdb_force_quit, NULL); | |
270 | Tcl_CreateObjCommand (interp, "gdb_target_has_execution", | |
271 | call_wrapper, | |
272 | gdb_target_has_execution_command, NULL); | |
273 | Tcl_CreateObjCommand (interp, "gdb_is_tracing", | |
274 | call_wrapper, gdb_trace_status, | |
275 | NULL); | |
276 | Tcl_CreateObjCommand (interp, "gdb_load_info", call_wrapper, gdb_load_info, NULL); | |
277 | Tcl_CreateObjCommand (interp, "gdb_get_locals", call_wrapper, gdb_get_locals_command, | |
278 | NULL); | |
279 | Tcl_CreateObjCommand (interp, "gdb_get_args", call_wrapper, gdb_get_args_command, | |
280 | NULL); | |
281 | Tcl_CreateObjCommand (interp, "gdb_get_function", call_wrapper, gdb_get_function_command, | |
282 | NULL); | |
283 | Tcl_CreateObjCommand (interp, "gdb_get_line", call_wrapper, gdb_get_line_command, | |
284 | NULL); | |
285 | Tcl_CreateObjCommand (interp, "gdb_get_file", call_wrapper, gdb_get_file_command, | |
286 | NULL); | |
287 | Tcl_CreateObjCommand (interp, "gdb_tracepoint_exists", | |
288 | call_wrapper, gdb_tracepoint_exists_command, NULL); | |
289 | Tcl_CreateObjCommand (interp, "gdb_get_tracepoint_info", | |
290 | call_wrapper, gdb_get_tracepoint_info, NULL); | |
291 | Tcl_CreateObjCommand (interp, "gdb_actions", | |
292 | call_wrapper, gdb_actions_command, NULL); | |
293 | Tcl_CreateObjCommand (interp, "gdb_prompt", | |
294 | call_wrapper, gdb_prompt_command, NULL); | |
295 | Tcl_CreateObjCommand (interp, "gdb_find_file", | |
296 | call_wrapper, gdb_find_file_command, NULL); | |
297 | Tcl_CreateObjCommand (interp, "gdb_get_tracepoint_list", | |
298 | call_wrapper, gdb_get_tracepoint_list, NULL); | |
299 | Tcl_CreateObjCommand (interp, "gdb_pc_reg", call_wrapper, get_pc_register, NULL); | |
300 | Tcl_CreateObjCommand (interp, "gdb_loadfile", call_wrapper, gdb_loadfile, NULL); | |
301 | Tcl_CreateObjCommand (gdbtk_interp, "gdb_search", call_wrapper, | |
302 | gdb_search, NULL); | |
303 | Tcl_CreateObjCommand (interp, "gdb_set_bp", call_wrapper, gdb_set_bp, NULL); | |
304 | Tcl_CreateObjCommand (interp, "gdb_get_trace_frame_num", | |
305 | call_wrapper, gdb_get_trace_frame_num, NULL); | |
306 | ||
307 | Tcl_PkgProvide(interp, "Gdbtk", GDBTK_VERSION); | |
308 | return TCL_OK; | |
309 | } | |
310 | ||
311 | /* This routine acts as a top-level for all GDB code called by Tcl/Tk. It | |
312 | handles cleanups, and uses catch_errors to trap calls to return_to_top_level | |
313 | (usually via error). | |
314 | This is necessary in order to prevent a longjmp out of the bowels of Tk, | |
315 | possibly leaving things in a bad state. Since this routine can be called | |
316 | recursively, it needs to save and restore the contents of the result_ptr as | |
317 | necessary. */ | |
318 | ||
319 | static int | |
320 | call_wrapper (clientData, interp, objc, objv) | |
321 | ClientData clientData; | |
322 | Tcl_Interp *interp; | |
323 | int objc; | |
324 | Tcl_Obj *CONST objv[]; | |
325 | { | |
326 | struct wrapped_call_args wrapped_args; | |
327 | gdbtk_result new_result, *old_result_ptr; | |
328 | int length; | |
329 | ||
330 | old_result_ptr = result_ptr; | |
331 | result_ptr = &new_result; | |
332 | result_ptr->obj_ptr = Tcl_NewObj(); | |
333 | result_ptr->flags = GDBTK_TO_RESULT; | |
334 | ||
335 | wrapped_args.func = (Tcl_ObjCmdProc *) clientData; | |
336 | wrapped_args.interp = interp; | |
337 | wrapped_args.objc = objc; | |
338 | wrapped_args.objv = objv; | |
339 | wrapped_args.val = TCL_OK; | |
340 | ||
341 | if (!catch_errors (wrapped_call, &wrapped_args, "", RETURN_MASK_ALL)) | |
342 | { | |
343 | ||
344 | wrapped_args.val = TCL_ERROR; /* Flag an error for TCL */ | |
345 | ||
346 | /* Make sure the timer interrupts are turned off. */ | |
347 | ||
348 | gdbtk_stop_timer (); | |
349 | ||
350 | gdb_flush (gdb_stderr); /* Flush error output */ | |
351 | gdb_flush (gdb_stdout); /* Sometimes error output comes here as well */ | |
352 | ||
353 | /* If we errored out here, and the results were going to the | |
354 | console, then gdbtk_fputs will have gathered the result into the | |
355 | result_ptr. We also need to echo them out to the console here */ | |
356 | ||
357 | gdb_flush (gdb_stderr); /* Flush error output */ | |
358 | gdb_flush (gdb_stdout); /* Sometimes error output comes here as well */ | |
359 | ||
360 | /* In case of an error, we may need to force the GUI into idle | |
361 | mode because gdbtk_call_command may have bombed out while in | |
362 | the command routine. */ | |
363 | ||
364 | running_now = 0; | |
365 | Tcl_Eval (interp, "gdbtk_tcl_idle"); | |
366 | ||
367 | } | |
368 | ||
369 | /* do not suppress any errors -- a remote target could have errored */ | |
370 | load_in_progress = 0; | |
371 | ||
372 | /* | |
373 | * Now copy the result over to the true Tcl result. If GDBTK_TO_RESULT flag | |
374 | * bit is set , this just copies a null object over to the Tcl result, which is | |
375 | * fine because we should reset the result in this case anyway. | |
376 | */ | |
377 | if (result_ptr->flags & GDBTK_IN_TCL_RESULT) | |
378 | { | |
379 | Tcl_DecrRefCount(result_ptr->obj_ptr); | |
380 | } | |
381 | else | |
382 | { | |
383 | Tcl_SetObjResult (interp, result_ptr->obj_ptr); | |
384 | } | |
385 | ||
386 | result_ptr = old_result_ptr; | |
387 | ||
388 | #ifdef _WIN32 | |
389 | close_bfds (); | |
390 | #endif | |
391 | ||
392 | return wrapped_args.val; | |
393 | } | |
394 | ||
395 | /* | |
396 | * This is the wrapper that is passed to catch_errors. | |
397 | */ | |
398 | ||
399 | static int | |
400 | wrapped_call (opaque_args) | |
401 | char *opaque_args; | |
402 | { | |
403 | struct wrapped_call_args *args = (struct wrapped_call_args *) opaque_args; | |
404 | args->val = (*args->func) (args->func, args->interp, args->objc, args->objv); | |
405 | return 1; | |
406 | } | |
407 | ||
408 | /* This is a convenience function to sprintf something(s) into a | |
409 | * new element in a Tcl list object. | |
410 | */ | |
411 | ||
412 | static void | |
413 | #ifdef ANSI_PROTOTYPES | |
414 | sprintf_append_element_to_obj (Tcl_Obj *objp, char *format, ...) | |
415 | #else | |
416 | sprintf_append_element_to_obj (va_alist) | |
417 | va_dcl | |
418 | #endif | |
419 | { | |
420 | va_list args; | |
421 | char buf[1024]; | |
422 | ||
423 | #ifdef ANSI_PROTOTYPES | |
424 | va_start (args, format); | |
425 | #else | |
426 | Tcl_Obj *objp; | |
427 | char *format; | |
428 | ||
429 | va_start (args); | |
430 | dsp = va_arg (args, Tcl_Obj *); | |
431 | format = va_arg (args, char *); | |
432 | #endif | |
433 | ||
434 | vsprintf (buf, format, args); | |
435 | ||
436 | Tcl_ListObjAppendElement (NULL, objp, Tcl_NewStringObj (buf, -1)); | |
437 | } | |
438 | \f | |
439 | /* | |
440 | * This section contains the commands that control execution. | |
441 | */ | |
442 | ||
443 | /* This implements the tcl command gdb_clear_file. | |
444 | * | |
445 | * Prepare to accept a new executable file. This is called when we | |
446 | * want to clear away everything we know about the old file, without | |
447 | * asking the user. The Tcl code will have already asked the user if | |
448 | * necessary. After this is called, we should be able to run the | |
449 | * `file' command without getting any questions. | |
450 | * | |
451 | * Arguments: | |
452 | * None | |
453 | * Tcl Result: | |
454 | * None | |
455 | */ | |
456 | ||
457 | static int | |
458 | gdb_clear_file (clientData, interp, objc, objv) | |
459 | ClientData clientData; | |
460 | Tcl_Interp *interp; | |
461 | int objc; | |
462 | Tcl_Obj *CONST objv[]; | |
463 | { | |
464 | if (objc != 1) | |
465 | Tcl_SetStringObj (result_ptr->obj_ptr, | |
466 | "Wrong number of args, none are allowed.", -1); | |
467 | ||
468 | if (inferior_pid != 0 && target_has_execution) | |
469 | { | |
470 | if (attach_flag) | |
471 | target_detach (NULL, 0); | |
472 | else | |
473 | target_kill (); | |
474 | } | |
475 | ||
476 | if (target_has_execution) | |
477 | pop_target (); | |
478 | ||
479 | symbol_file_command (NULL, 0); | |
480 | ||
481 | /* gdb_loc refers to stop_pc, but nothing seems to clear it, so we | |
482 | clear it here. FIXME: This seems like an abstraction violation | |
483 | somewhere. */ | |
484 | stop_pc = 0; | |
485 | ||
486 | return TCL_OK; | |
487 | } | |
488 | ||
489 | /* This implements the tcl command gdb_confirm_quit | |
490 | * Ask the user to confirm an exit request. | |
491 | * | |
492 | * Arguments: | |
493 | * None | |
494 | * Tcl Result: | |
495 | * A boolean, 1 if the user answered yes, 0 if no. | |
496 | */ | |
497 | ||
498 | static int | |
499 | gdb_confirm_quit (clientData, interp, objc, objv) | |
500 | ClientData clientData; | |
501 | Tcl_Interp *interp; | |
502 | int objc; | |
503 | Tcl_Obj *CONST objv[]; | |
504 | { | |
505 | int ret; | |
506 | ||
507 | if (objc != 1) | |
508 | { | |
509 | Tcl_SetStringObj (result_ptr->obj_ptr, "Wrong number of args, should be none.", -1); | |
510 | return TCL_ERROR; | |
511 | } | |
512 | ||
513 | ret = quit_confirm (); | |
514 | Tcl_SetBooleanObj (result_ptr->obj_ptr, ret); | |
515 | return TCL_OK; | |
516 | } | |
517 | ||
518 | /* This implements the tcl command gdb_force_quit | |
519 | * Quit without asking for confirmation. | |
520 | * | |
521 | * Arguments: | |
522 | * None | |
523 | * Tcl Result: | |
524 | * None | |
525 | */ | |
526 | ||
527 | static int | |
528 | gdb_force_quit (clientData, interp, objc, objv) | |
529 | ClientData clientData; | |
530 | Tcl_Interp *interp; | |
531 | int objc; | |
532 | Tcl_Obj *CONST objv[]; | |
533 | { | |
534 | if (objc != 1) | |
535 | { | |
536 | Tcl_SetStringObj (result_ptr->obj_ptr, "Wrong number of args, should be none.", -1); | |
537 | return TCL_ERROR; | |
538 | } | |
539 | ||
540 | quit_force ((char *) NULL, 1); | |
541 | return TCL_OK; | |
542 | } | |
543 | ||
544 | /* This implements the tcl command gdb_stop | |
545 | * It stops the target in a continuable fashion. | |
546 | * | |
547 | * Arguments: | |
548 | * None | |
549 | * Tcl Result: | |
550 | * None | |
551 | */ | |
552 | ||
553 | static int | |
554 | gdb_stop (clientData, interp, objc, objv) | |
555 | ClientData clientData; | |
556 | Tcl_Interp *interp; | |
557 | int objc; | |
558 | Tcl_Obj *CONST objv[]; | |
559 | { | |
560 | if (target_stop) | |
561 | { | |
562 | target_stop (); | |
563 | } | |
564 | else | |
565 | quit_flag = 1; /* hope something sees this */ | |
566 | ||
567 | return TCL_OK; | |
568 | } | |
569 | ||
570 | \f | |
571 | /* | |
572 | * This section contains Tcl commands that are wrappers for invoking | |
573 | * the GDB command interpreter. | |
574 | */ | |
575 | ||
576 | ||
577 | /* This implements the tcl command `gdb_eval'. | |
578 | * It uses the gdb evaluator to return the value of | |
579 | * an expression in the current language | |
580 | * | |
581 | * Tcl Arguments: | |
582 | * expression - the expression to evaluate. | |
583 | * Tcl Result: | |
584 | * The result of the evaluation. | |
585 | */ | |
586 | ||
587 | static int | |
588 | gdb_eval (clientData, interp, objc, objv) | |
589 | ClientData clientData; | |
590 | Tcl_Interp *interp; | |
591 | int objc; | |
592 | Tcl_Obj *CONST objv[]; | |
593 | { | |
594 | struct expression *expr; | |
595 | struct cleanup *old_chain; | |
596 | value_ptr val; | |
597 | ||
598 | if (objc != 2) | |
599 | { | |
600 | Tcl_SetStringObj (result_ptr->obj_ptr, | |
601 | "wrong # args, should be \"gdb_eval expression\"", -1); | |
602 | return TCL_ERROR; | |
603 | } | |
604 | ||
605 | expr = parse_expression (Tcl_GetStringFromObj (objv[1], NULL)); | |
606 | ||
607 | old_chain = make_cleanup (free_current_contents, &expr); | |
608 | ||
609 | val = evaluate_expression (expr); | |
610 | ||
611 | /* | |
612 | * Print the result of the expression evaluation. This will go to | |
613 | * eventually go to gdbtk_fputs, and from there be collected into | |
614 | * the Tcl result. | |
615 | */ | |
616 | ||
617 | val_print (VALUE_TYPE (val), VALUE_CONTENTS (val), VALUE_ADDRESS (val), | |
618 | gdb_stdout, 0, 0, 0, 0); | |
619 | ||
620 | do_cleanups (old_chain); | |
621 | ||
622 | return TCL_OK; | |
623 | } | |
624 | ||
625 | /* This implements the tcl command "gdb_cmd". | |
626 | * | |
627 | * It sends its argument to the GDB command scanner for execution. | |
628 | * This command will never cause the update, idle and busy hooks to be called | |
629 | * within the GUI. | |
630 | * | |
631 | * Tcl Arguments: | |
632 | * command - The GDB command to execute | |
633 | * Tcl Result: | |
634 | * The output from the gdb command (except for the "load" & "while" | |
635 | * which dump their output to the console. | |
636 | */ | |
637 | ||
638 | static int | |
639 | gdb_cmd (clientData, interp, objc, objv) | |
640 | ClientData clientData; | |
641 | Tcl_Interp *interp; | |
642 | int objc; | |
643 | Tcl_Obj *CONST objv[]; | |
644 | { | |
645 | ||
646 | if (objc < 2) | |
647 | { | |
648 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong # args", -1); | |
649 | return TCL_ERROR; | |
650 | } | |
651 | ||
652 | if (running_now || load_in_progress) | |
653 | return TCL_OK; | |
654 | ||
655 | No_Update = 1; | |
656 | ||
657 | /* for the load instruction (and possibly others later) we | |
658 | set turn off the GDBTK_TO_RESULT flag bit so gdbtk_fputs() | |
659 | will not buffer all the data until the command is finished. */ | |
660 | ||
661 | if ((strncmp ("load ", Tcl_GetStringFromObj (objv[1], NULL), 5) == 0) | |
662 | || (strncmp ("while ", Tcl_GetStringFromObj (objv[1], NULL), 6) == 0)) | |
663 | { | |
664 | result_ptr->flags &= ~GDBTK_TO_RESULT; | |
665 | load_in_progress = 1; | |
666 | gdbtk_start_timer (); | |
667 | } | |
668 | ||
669 | execute_command (Tcl_GetStringFromObj (objv[1], NULL), 1); | |
670 | ||
671 | if (load_in_progress) | |
672 | { | |
673 | gdbtk_stop_timer (); | |
674 | load_in_progress = 0; | |
675 | result_ptr->flags |= GDBTK_TO_RESULT; | |
676 | } | |
677 | ||
678 | bpstat_do_actions (&stop_bpstat); | |
679 | ||
680 | return TCL_OK; | |
681 | } | |
682 | ||
683 | /* | |
684 | * This implements the tcl command "gdb_immediate" | |
685 | * | |
686 | * It does exactly the same thing as gdb_cmd, except NONE of its outut | |
687 | * is buffered. This will also ALWAYS cause the busy, update, and idle hooks to | |
688 | * be called, contrasted with gdb_cmd, which NEVER calls them. | |
689 | * It turns off the GDBTK_TO_RESULT flag, which diverts the result | |
690 | * to the console window. | |
691 | * | |
692 | * Tcl Arguments: | |
693 | * command - The GDB command to execute | |
694 | * Tcl Result: | |
695 | * None. | |
696 | */ | |
697 | ||
698 | static int | |
699 | gdb_immediate_command (clientData, interp, objc, objv) | |
700 | ClientData clientData; | |
701 | Tcl_Interp *interp; | |
702 | int objc; | |
703 | Tcl_Obj *CONST objv[]; | |
704 | { | |
705 | ||
706 | if (objc != 2) | |
707 | { | |
708 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong # args", -1); | |
709 | return TCL_ERROR; | |
710 | } | |
711 | ||
712 | if (running_now || load_in_progress) | |
713 | return TCL_OK; | |
714 | ||
715 | No_Update = 0; | |
716 | ||
717 | result_ptr->flags &= ~GDBTK_TO_RESULT; | |
718 | ||
719 | execute_command (Tcl_GetStringFromObj (objv[1], NULL), 1); | |
720 | ||
721 | bpstat_do_actions (&stop_bpstat); | |
722 | ||
723 | result_ptr->flags |= GDBTK_TO_RESULT; | |
724 | ||
725 | return TCL_OK; | |
726 | } | |
727 | ||
728 | /* This implements the tcl command "gdb_prompt" | |
729 | * | |
730 | * It returns the gdb interpreter's prompt. | |
731 | * | |
732 | * Tcl Arguments: | |
733 | * None. | |
734 | * Tcl Result: | |
735 | * The prompt. | |
736 | */ | |
737 | ||
738 | static int | |
739 | gdb_prompt_command (clientData, interp, objc, objv) | |
740 | ClientData clientData; | |
741 | Tcl_Interp *interp; | |
742 | int objc; | |
743 | Tcl_Obj *CONST objv[]; | |
744 | { | |
745 | Tcl_SetStringObj (result_ptr->obj_ptr, get_prompt (), -1); | |
746 | return TCL_OK; | |
747 | } | |
748 | ||
749 | \f | |
750 | /* | |
751 | * This section contains general informational commands. | |
752 | */ | |
753 | ||
754 | /* This implements the tcl command "gdb_target_has_execution" | |
755 | * | |
756 | * Tells whether the target is executing. | |
757 | * | |
758 | * Tcl Arguments: | |
759 | * None | |
760 | * Tcl Result: | |
761 | * A boolean indicating whether the target is executing. | |
762 | */ | |
763 | ||
764 | static int | |
765 | gdb_target_has_execution_command (clientData, interp, objc, objv) | |
766 | ClientData clientData; | |
767 | Tcl_Interp *interp; | |
768 | int objc; | |
769 | Tcl_Obj *CONST objv[]; | |
770 | { | |
771 | int result = 0; | |
772 | ||
773 | if (target_has_execution && inferior_pid != 0) | |
774 | result = 1; | |
775 | ||
776 | Tcl_SetBooleanObj (result_ptr->obj_ptr, result); | |
777 | return TCL_OK; | |
778 | } | |
779 | ||
780 | /* This implements the tcl command "gdb_load_info" | |
781 | * | |
782 | * It returns information about the file about to be downloaded. | |
783 | * | |
784 | * Tcl Arguments: | |
785 | * filename: The file to open & get the info on. | |
786 | * Tcl Result: | |
787 | * A list consisting of the name and size of each section. | |
788 | */ | |
789 | ||
790 | static int | |
791 | gdb_load_info (clientData, interp, objc, objv) | |
792 | ClientData clientData; | |
793 | Tcl_Interp *interp; | |
794 | int objc; | |
795 | Tcl_Obj *CONST objv[]; | |
796 | { | |
797 | bfd *loadfile_bfd; | |
798 | struct cleanup *old_cleanups; | |
799 | asection *s; | |
800 | Tcl_Obj *ob[2]; | |
801 | int i = 0; | |
802 | ||
803 | char *filename = Tcl_GetStringFromObj (objv[1], NULL); | |
804 | ||
805 | loadfile_bfd = bfd_openr (filename, gnutarget); | |
806 | if (loadfile_bfd == NULL) | |
807 | { | |
808 | Tcl_SetStringObj (result_ptr->obj_ptr, "Open failed", -1); | |
809 | return TCL_ERROR; | |
810 | } | |
811 | old_cleanups = make_cleanup (bfd_close, loadfile_bfd); | |
812 | ||
813 | if (!bfd_check_format (loadfile_bfd, bfd_object)) | |
814 | { | |
815 | Tcl_SetStringObj (result_ptr->obj_ptr, "Bad Object File", -1); | |
816 | return TCL_ERROR; | |
817 | } | |
818 | ||
819 | Tcl_SetListObj (result_ptr->obj_ptr, 0, NULL); | |
820 | ||
821 | for (s = loadfile_bfd->sections; s; s = s->next) | |
822 | { | |
823 | if (s->flags & SEC_LOAD) | |
824 | { | |
825 | bfd_size_type size = bfd_get_section_size_before_reloc (s); | |
826 | if (size > 0) | |
827 | { | |
828 | ob[0] = Tcl_NewStringObj ((char *) bfd_get_section_name (loadfile_bfd, s), -1); | |
829 | ob[1] = Tcl_NewLongObj ((long) size); | |
830 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewListObj (2, ob)); | |
831 | } | |
832 | } | |
833 | } | |
834 | ||
835 | do_cleanups (old_cleanups); | |
836 | return TCL_OK; | |
837 | } | |
838 | ||
839 | ||
840 | /* gdb_get_locals - | |
841 | * This and gdb_get_locals just call gdb_get_vars_command with the right | |
842 | * value of clientData. We can't use the client data in the definition | |
843 | * of the command, because the call wrapper uses this instead... | |
844 | */ | |
845 | ||
846 | static int | |
847 | gdb_get_locals_command (clientData, interp, objc, objv) | |
848 | ClientData clientData; | |
849 | Tcl_Interp *interp; | |
850 | int objc; | |
851 | Tcl_Obj *CONST objv[]; | |
852 | { | |
853 | ||
854 | return gdb_get_vars_command((ClientData) 0, interp, objc, objv); | |
855 | ||
856 | } | |
857 | ||
858 | static int | |
859 | gdb_get_args_command (clientData, interp, objc, objv) | |
860 | ClientData clientData; | |
861 | Tcl_Interp *interp; | |
862 | int objc; | |
863 | Tcl_Obj *CONST objv[]; | |
864 | { | |
865 | ||
866 | return gdb_get_vars_command((ClientData) 1, interp, objc, objv); | |
867 | ||
868 | } | |
869 | ||
870 | /* This implements the tcl commands "gdb_get_locals" and "gdb_get_args" | |
871 | * | |
872 | * This function sets the Tcl interpreter's result to a list of variable names | |
873 | * depending on clientData. If clientData is one, the result is a list of | |
874 | * arguments; zero returns a list of locals -- all relative to the block | |
875 | * specified as an argument to the command. Valid commands include | |
876 | * anything decode_line_1 can handle (like "main.c:2", "*0x02020202", | |
877 | * and "main"). | |
878 | * | |
879 | * Tcl Arguments: | |
880 | * block - the address within which to specify the locals or args. | |
881 | * Tcl Result: | |
882 | * A list of the locals or args | |
883 | */ | |
884 | ||
885 | static int | |
886 | gdb_get_vars_command (clientData, interp, objc, objv) | |
887 | ClientData clientData; | |
888 | Tcl_Interp *interp; | |
889 | int objc; | |
890 | Tcl_Obj *CONST objv[]; | |
891 | { | |
892 | struct symtabs_and_lines sals; | |
893 | struct symbol *sym; | |
894 | struct block *block; | |
895 | char **canonical, *args; | |
896 | int i, nsyms, arguments; | |
897 | ||
898 | if (objc != 2) | |
899 | { | |
900 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, | |
901 | "wrong # of args: should be \"", | |
902 | Tcl_GetStringFromObj (objv[0], NULL), | |
903 | " function:line|function|line|*addr\"", NULL); | |
904 | return TCL_ERROR; | |
905 | } | |
906 | ||
907 | arguments = (int) clientData; | |
908 | args = Tcl_GetStringFromObj (objv[1], NULL); | |
909 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
910 | if (sals.nelts == 0) | |
911 | { | |
912 | Tcl_SetStringObj (result_ptr->obj_ptr, | |
913 | "error decoding line", -1); | |
914 | return TCL_ERROR; | |
915 | } | |
916 | ||
917 | /* Initialize the result pointer to an empty list. */ | |
918 | ||
919 | Tcl_SetListObj (result_ptr->obj_ptr, 0, NULL); | |
920 | ||
921 | /* Resolve all line numbers to PC's */ | |
922 | for (i = 0; i < sals.nelts; i++) | |
923 | resolve_sal_pc (&sals.sals[i]); | |
924 | ||
925 | block = block_for_pc (sals.sals[0].pc); | |
926 | while (block != 0) | |
927 | { | |
928 | nsyms = BLOCK_NSYMS (block); | |
929 | for (i = 0; i < nsyms; i++) | |
930 | { | |
931 | sym = BLOCK_SYM (block, i); | |
932 | switch (SYMBOL_CLASS (sym)) { | |
933 | default: | |
934 | case LOC_UNDEF: /* catches errors */ | |
935 | case LOC_CONST: /* constant */ | |
936 | case LOC_STATIC: /* static */ | |
937 | case LOC_REGISTER: /* register */ | |
938 | case LOC_TYPEDEF: /* local typedef */ | |
939 | case LOC_LABEL: /* local label */ | |
940 | case LOC_BLOCK: /* local function */ | |
941 | case LOC_CONST_BYTES: /* loc. byte seq. */ | |
942 | case LOC_UNRESOLVED: /* unresolved static */ | |
943 | case LOC_OPTIMIZED_OUT: /* optimized out */ | |
944 | break; | |
945 | case LOC_ARG: /* argument */ | |
946 | case LOC_REF_ARG: /* reference arg */ | |
947 | case LOC_REGPARM: /* register arg */ | |
948 | case LOC_REGPARM_ADDR: /* indirect register arg */ | |
949 | case LOC_LOCAL_ARG: /* stack arg */ | |
950 | case LOC_BASEREG_ARG: /* basereg arg */ | |
951 | if (arguments) | |
952 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, | |
953 | Tcl_NewStringObj (SYMBOL_NAME (sym), -1)); | |
954 | break; | |
955 | case LOC_LOCAL: /* stack local */ | |
956 | case LOC_BASEREG: /* basereg local */ | |
957 | if (!arguments) | |
958 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, | |
959 | Tcl_NewStringObj (SYMBOL_NAME (sym), -1)); | |
960 | break; | |
961 | } | |
962 | } | |
963 | if (BLOCK_FUNCTION (block)) | |
964 | break; | |
965 | else | |
966 | block = BLOCK_SUPERBLOCK (block); | |
967 | } | |
968 | ||
969 | return TCL_OK; | |
970 | } | |
971 | ||
972 | /* This implements the tcl command "gdb_get_line" | |
973 | * | |
974 | * It returns the linenumber for a given linespec. It will take any spec | |
975 | * that can be passed to decode_line_1 | |
976 | * | |
977 | * Tcl Arguments: | |
978 | * linespec - the line specification | |
979 | * Tcl Result: | |
980 | * The line number for that spec. | |
981 | */ | |
982 | static int | |
983 | gdb_get_line_command (clientData, interp, objc, objv) | |
984 | ClientData clientData; | |
985 | Tcl_Interp *interp; | |
986 | int objc; | |
987 | Tcl_Obj *CONST objv[]; | |
988 | { | |
989 | Tcl_Obj *result; | |
990 | struct symtabs_and_lines sals; | |
991 | char *args, **canonical; | |
992 | ||
993 | if (objc != 2) | |
994 | { | |
995 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # of args: should be \"", | |
996 | Tcl_GetStringFromObj (objv[0], NULL), | |
997 | " linespec\"", NULL); | |
998 | return TCL_ERROR; | |
999 | } | |
1000 | ||
1001 | args = Tcl_GetStringFromObj (objv[1], NULL); | |
1002 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
1003 | if (sals.nelts == 1) | |
1004 | { | |
1005 | Tcl_SetIntObj (result_ptr->obj_ptr, sals.sals[0].line); | |
1006 | return TCL_OK; | |
1007 | } | |
1008 | ||
1009 | Tcl_SetStringObj (result_ptr->obj_ptr, "N/A", -1); | |
1010 | return TCL_OK; | |
1011 | ||
1012 | } | |
1013 | ||
1014 | /* This implements the tcl command "gdb_get_file" | |
1015 | * | |
1016 | * It returns the file containing a given line spec. | |
1017 | * | |
1018 | * Tcl Arguments: | |
1019 | * linespec - The linespec to look up | |
1020 | * Tcl Result: | |
1021 | * The file containing it. | |
1022 | */ | |
1023 | ||
1024 | static int | |
1025 | gdb_get_file_command (clientData, interp, objc, objv) | |
1026 | ClientData clientData; | |
1027 | Tcl_Interp *interp; | |
1028 | int objc; | |
1029 | Tcl_Obj *CONST objv[]; | |
1030 | { | |
1031 | Tcl_Obj *result; | |
1032 | struct symtabs_and_lines sals; | |
1033 | char *args, **canonical; | |
1034 | ||
1035 | if (objc != 2) | |
1036 | { | |
1037 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # of args: should be \"", | |
1038 | Tcl_GetStringFromObj (objv[0], NULL), | |
1039 | " linespec\"", NULL); | |
1040 | return TCL_ERROR; | |
1041 | } | |
1042 | ||
1043 | args = Tcl_GetStringFromObj (objv[1], NULL); | |
1044 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
1045 | if (sals.nelts == 1) | |
1046 | { | |
1047 | Tcl_SetStringObj (result_ptr->obj_ptr, sals.sals[0].symtab->filename, -1); | |
1048 | return TCL_OK; | |
1049 | } | |
1050 | ||
1051 | Tcl_SetStringObj (result_ptr->obj_ptr, "N/A", -1); | |
1052 | return TCL_OK; | |
1053 | } | |
1054 | ||
1055 | /* This implements the tcl command "gdb_get_function" | |
1056 | * | |
1057 | * It finds the function containing the given line spec. | |
1058 | * | |
1059 | * Tcl Arguments: | |
1060 | * linespec - The line specification | |
1061 | * Tcl Result: | |
1062 | * The function that contains it, or "N/A" if it is not in a function. | |
1063 | */ | |
1064 | static int | |
1065 | gdb_get_function_command (clientData, interp, objc, objv) | |
1066 | ClientData clientData; | |
1067 | Tcl_Interp *interp; | |
1068 | int objc; | |
1069 | Tcl_Obj *CONST objv[]; | |
1070 | { | |
1071 | char *function; | |
1072 | struct symtabs_and_lines sals; | |
1073 | char *args, **canonical; | |
1074 | ||
1075 | if (objc != 2) | |
1076 | { | |
1077 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # of args: should be \"", | |
1078 | Tcl_GetStringFromObj (objv[0], NULL), | |
1079 | " linespec\"", NULL); | |
1080 | return TCL_ERROR; | |
1081 | } | |
1082 | ||
1083 | args = Tcl_GetStringFromObj (objv[1], NULL); | |
1084 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
1085 | if (sals.nelts == 1) | |
1086 | { | |
1087 | resolve_sal_pc (&sals.sals[0]); | |
1088 | find_pc_partial_function (sals.sals[0].pc, &function, NULL, NULL); | |
1089 | if (function != NULL) | |
1090 | { | |
1091 | Tcl_SetStringObj (result_ptr->obj_ptr, function, -1); | |
1092 | return TCL_OK; | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | Tcl_SetStringObj (result_ptr->obj_ptr, "N/A", -1); | |
1097 | return TCL_OK; | |
1098 | } | |
1099 | ||
1100 | /* This implements the tcl command "gdb_find_file" | |
1101 | * | |
1102 | * It searches the symbol tables to get the full pathname to a file. | |
1103 | * | |
1104 | * Tcl Arguments: | |
1105 | * filename: the file name to search for. | |
1106 | * Tcl Result: | |
1107 | * The full path to the file, or an empty string if the file is not | |
1108 | * found. | |
1109 | */ | |
1110 | ||
1111 | static int | |
1112 | gdb_find_file_command (clientData, interp, objc, objv) | |
1113 | ClientData clientData; | |
1114 | Tcl_Interp *interp; | |
1115 | int objc; | |
1116 | Tcl_Obj *CONST objv[]; | |
1117 | { | |
1118 | char *filename = NULL; | |
1119 | struct symtab *st; | |
1120 | ||
1121 | if (objc != 2) | |
1122 | { | |
1123 | Tcl_WrongNumArgs(interp, 1, objv, "filename"); | |
1124 | return TCL_ERROR; | |
1125 | } | |
1126 | ||
1127 | st = full_lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL)); | |
1128 | if (st) | |
1129 | filename = st->fullname; | |
1130 | ||
1131 | if (filename == NULL) | |
1132 | Tcl_SetStringObj (result_ptr->obj_ptr, "", 0); | |
1133 | else | |
1134 | Tcl_SetStringObj (result_ptr->obj_ptr, filename, -1); | |
1135 | ||
1136 | return TCL_OK; | |
1137 | } | |
1138 | ||
1139 | /* This implements the tcl command "gdb_listfiles" | |
1140 | * | |
1141 | * This lists all the files in the current executible. | |
1142 | * | |
1143 | * Arguments: | |
1144 | * ?pathname? - If provided, only files which match pathname | |
1145 | * (up to strlen(pathname)) are included. | |
1146 | * Tcl Result: | |
1147 | * A list of all matching files. | |
1148 | */ | |
1149 | ||
1150 | static int | |
1151 | gdb_listfiles (clientData, interp, objc, objv) | |
1152 | ClientData clientData; | |
1153 | Tcl_Interp *interp; | |
1154 | int objc; | |
1155 | Tcl_Obj *CONST objv[]; | |
1156 | { | |
1157 | struct objfile *objfile; | |
1158 | struct partial_symtab *psymtab; | |
1159 | struct symtab *symtab; | |
1160 | char *lastfile, *pathname, **files; | |
1161 | int files_size; | |
1162 | int i, numfiles = 0, len = 0; | |
1163 | Tcl_Obj *mylist; | |
1164 | ||
1165 | files_size = 1000; | |
1166 | files = (char **) xmalloc (sizeof (char *) * files_size); | |
1167 | ||
1168 | if (objc > 2) | |
1169 | { | |
1170 | Tcl_WrongNumArgs (interp, 1, objv, "Usage: gdb_listfiles ?pathname?"); | |
1171 | return TCL_ERROR; | |
1172 | } | |
1173 | else if (objc == 2) | |
1174 | pathname = Tcl_GetStringFromObj (objv[1], &len); | |
1175 | ||
1176 | ALL_PSYMTABS (objfile, psymtab) | |
1177 | { | |
1178 | if (numfiles == files_size) | |
1179 | { | |
1180 | files_size = files_size * 2; | |
1181 | files = (char **) xrealloc (files, sizeof (char *) * files_size); | |
1182 | } | |
1183 | if (len == 0) | |
1184 | { | |
1185 | if (psymtab->filename) | |
1186 | files[numfiles++] = basename(psymtab->filename); | |
1187 | } | |
1188 | else if (!strcmp(psymtab->filename,basename(psymtab->filename)) | |
1189 | || !strncmp(pathname,psymtab->filename,len)) | |
1190 | if (psymtab->filename) | |
1191 | files[numfiles++] = basename(psymtab->filename); | |
1192 | } | |
1193 | ||
1194 | ALL_SYMTABS (objfile, symtab) | |
1195 | { | |
1196 | if (numfiles == files_size) | |
1197 | { | |
1198 | files_size = files_size * 2; | |
1199 | files = (char **) xrealloc (files, sizeof (char *) * files_size); | |
1200 | } | |
1201 | if (len == 0) | |
1202 | { | |
1203 | if (symtab->filename) | |
1204 | files[numfiles++] = basename(symtab->filename); | |
1205 | } | |
1206 | else if (!strcmp(symtab->filename,basename(symtab->filename)) | |
1207 | || !strncmp(pathname,symtab->filename,len)) | |
1208 | if (symtab->filename) | |
1209 | files[numfiles++] = basename(symtab->filename); | |
1210 | } | |
1211 | ||
1212 | qsort (files, numfiles, sizeof(char *), comp_files); | |
1213 | ||
1214 | lastfile = ""; | |
1215 | ||
1216 | /* Discard the old result pointer, in case it has accumulated anything | |
1217 | and set it to a new list object */ | |
1218 | ||
1219 | Tcl_SetListObj(result_ptr->obj_ptr, 0, NULL); | |
1220 | ||
1221 | for (i = 0; i < numfiles; i++) | |
1222 | { | |
1223 | if (strcmp(files[i],lastfile)) | |
1224 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewStringObj(files[i], -1)); | |
1225 | lastfile = files[i]; | |
1226 | } | |
1227 | ||
1228 | free (files); | |
1229 | return TCL_OK; | |
1230 | } | |
1231 | ||
1232 | static int | |
1233 | comp_files (file1, file2) | |
1234 | const void *file1, *file2; | |
1235 | { | |
1236 | return strcmp(* (char **) file1, * (char **) file2); | |
1237 | } | |
1238 | ||
1239 | ||
1240 | /* This implements the tcl command "gdb_search" | |
1241 | * | |
1242 | * | |
1243 | * Tcl Arguments: | |
1244 | * option - One of "functions", "variables" or "types" | |
1245 | * regexp - The regular expression to look for. | |
1246 | * Then, optionally: | |
1247 | * -files fileList | |
1248 | * -static 1/0 | |
1249 | * Tcl Result: | |
1250 | * | |
1251 | */ | |
1252 | ||
1253 | static int | |
1254 | gdb_search (clientData, interp, objc, objv) | |
1255 | ClientData clientData; | |
1256 | Tcl_Interp *interp; | |
1257 | int objc; | |
1258 | Tcl_Obj *CONST objv[]; | |
1259 | { | |
1260 | struct symbol_search *ss; | |
1261 | struct symbol_search *p; | |
1262 | struct cleanup *old_chain; | |
1263 | Tcl_Obj *list, *result, *CONST *switch_objv; | |
1264 | int index, switch_objc, i; | |
1265 | namespace_enum space; | |
1266 | char *regexp, *val; | |
1267 | int static_only, nfiles; | |
1268 | Tcl_Obj **file_list; | |
1269 | char **files; | |
1270 | static char *search_options[] = { "functions", "variables", "types", (char *) NULL }; | |
1271 | static char *switches[] = { "-files", "-static" }; | |
1272 | enum search_opts { SEARCH_FUNCTIONS, SEARCH_VARIABLES, SEARCH_TYPES }; | |
1273 | enum switches_opts { SWITCH_FILES, SWITCH_STATIC_ONLY }; | |
1274 | ||
1275 | if (objc < 3) | |
1276 | { | |
1277 | Tcl_WrongNumArgs (interp, 1, objv, "option regexp ?arg ...?"); | |
1278 | return TCL_ERROR; | |
1279 | } | |
1280 | ||
1281 | if (Tcl_GetIndexFromObj (interp, objv[1], search_options, "option", 0, | |
1282 | &index) != TCL_OK) | |
1283 | return TCL_ERROR; | |
1284 | ||
1285 | /* Unfortunately, we cannot teach search_symbols to search on | |
1286 | multiple regexps, so we have to do a two-tier search for | |
1287 | any searches which choose to narrow the playing field. */ | |
1288 | switch ((enum search_opts) index) | |
1289 | { | |
1290 | case SEARCH_FUNCTIONS: | |
1291 | space = FUNCTIONS_NAMESPACE; break; | |
1292 | case SEARCH_VARIABLES: | |
1293 | space = VARIABLES_NAMESPACE; break; | |
1294 | case SEARCH_TYPES: | |
1295 | space = TYPES_NAMESPACE; break; | |
1296 | } | |
1297 | ||
1298 | regexp = Tcl_GetStringFromObj (objv[2], NULL); | |
1299 | /* Process any switches that refine the search */ | |
1300 | switch_objc = objc - 3; | |
1301 | switch_objv = objv + 3; | |
1302 | ||
1303 | static_only = 0; | |
1304 | nfiles = 0; | |
1305 | files = (char **) NULL; | |
1306 | while (switch_objc > 0) | |
1307 | { | |
1308 | if (Tcl_GetIndexFromObj (interp, switch_objv[0], switches, | |
1309 | "option", 0, &index) != TCL_OK) | |
1310 | { | |
1311 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1312 | return TCL_ERROR; | |
1313 | } | |
1314 | ||
1315 | switch ((enum switches_opts) index) | |
1316 | { | |
1317 | case SWITCH_FILES: | |
1318 | if (switch_objc < 2) | |
1319 | { | |
1320 | Tcl_WrongNumArgs (interp, 2, objv, "[-files fileList -static 1|0]"); | |
1321 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1322 | return TCL_ERROR; | |
1323 | } | |
1324 | Tcl_ListObjGetElements (interp, switch_objv[1], &nfiles, &file_list); | |
1325 | files = (char **) xmalloc (nfiles); | |
1326 | old_chain = make_cleanup (free, files); | |
1327 | ||
1328 | for (i = 0; i < nfiles; i++) | |
1329 | files[i] = Tcl_GetStringFromObj (file_list[i], NULL); | |
1330 | switch_objc--; | |
1331 | switch_objv++; | |
1332 | break; | |
1333 | case SWITCH_STATIC_ONLY: | |
1334 | if (switch_objc < 2) | |
1335 | { | |
1336 | Tcl_WrongNumArgs (interp, 2, objv, "[-files fileList] [-static 1|0]"); | |
1337 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1338 | return TCL_ERROR; | |
1339 | } | |
1340 | if ( Tcl_GetBooleanFromObj (interp, switch_objv[1], &static_only) != | |
1341 | TCL_OK) { | |
1342 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1343 | return TCL_ERROR; | |
1344 | } | |
1345 | switch_objc--; | |
1346 | switch_objv++; | |
1347 | } | |
1348 | ||
1349 | switch_objc--; | |
1350 | switch_objv++; | |
1351 | } | |
1352 | ||
1353 | search_symbols (regexp, space, nfiles, files, &ss); | |
1354 | if (files != NULL && ss != NULL) | |
1355 | do_cleanups (old_chain); | |
1356 | old_chain = make_cleanup (free_search_symbols, ss); | |
1357 | ||
1358 | Tcl_SetListObj(result_ptr->obj_ptr, 0, NULL); | |
1359 | ||
1360 | for (p = ss; p != NULL; p = p->next) | |
1361 | { | |
1362 | Tcl_Obj *elem; | |
1363 | ||
1364 | if (static_only && p->block != STATIC_BLOCK) | |
1365 | continue; | |
1366 | ||
1367 | elem = Tcl_NewListObj (0, NULL); | |
1368 | ||
1369 | if (p->msymbol == NULL) | |
1370 | Tcl_ListObjAppendElement (interp, elem, | |
1371 | Tcl_NewStringObj (SYMBOL_SOURCE_NAME (p->symbol), -1)); | |
1372 | else | |
1373 | Tcl_ListObjAppendElement (interp, elem, | |
1374 | Tcl_NewStringObj (SYMBOL_SOURCE_NAME (p->msymbol), -1)); | |
1375 | ||
1376 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, elem); | |
1377 | } | |
1378 | ||
1379 | do_cleanups (old_chain); | |
1380 | return TCL_OK; | |
1381 | } | |
1382 | ||
1383 | /* This implements the tcl command gdb_listfuncs | |
1384 | * | |
1385 | * It lists all the functions defined in a given file | |
1386 | * | |
1387 | * Arguments: | |
1388 | * file - the file to look in | |
1389 | * Tcl Result: | |
1390 | * A list of two element lists, the first element is | |
1391 | * the symbol name, and the second is a boolean indicating | |
1392 | * whether the symbol is demangled (1 for yes). | |
1393 | */ | |
1394 | ||
1395 | static int | |
1396 | gdb_listfuncs (clientData, interp, objc, objv) | |
1397 | ClientData clientData; | |
1398 | Tcl_Interp *interp; | |
1399 | int objc; | |
1400 | Tcl_Obj *CONST objv[]; | |
1401 | { | |
1402 | struct symtab *symtab; | |
1403 | struct blockvector *bv; | |
1404 | struct block *b; | |
1405 | struct symbol *sym; | |
1406 | char buf[128]; | |
1407 | int i,j; | |
1408 | Tcl_Obj *funcVals[2]; | |
1409 | ||
1410 | if (objc != 2) | |
1411 | { | |
1412 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong # args", -1); | |
1413 | } | |
1414 | ||
1415 | symtab = full_lookup_symtab (Tcl_GetStringFromObj (objv[1], NULL)); | |
1416 | if (!symtab) | |
1417 | { | |
1418 | Tcl_SetStringObj (result_ptr->obj_ptr, "No such file", -1); | |
1419 | return TCL_ERROR; | |
1420 | } | |
1421 | ||
1422 | if (mangled == NULL) | |
1423 | { | |
1424 | mangled = Tcl_NewBooleanObj(1); | |
1425 | not_mangled = Tcl_NewBooleanObj(0); | |
1426 | Tcl_IncrRefCount(mangled); | |
1427 | Tcl_IncrRefCount(not_mangled); | |
1428 | } | |
1429 | ||
1430 | Tcl_SetListObj (result_ptr->obj_ptr, 0, NULL); | |
1431 | ||
1432 | bv = BLOCKVECTOR (symtab); | |
1433 | for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++) | |
1434 | { | |
1435 | b = BLOCKVECTOR_BLOCK (bv, i); | |
1436 | /* Skip the sort if this block is always sorted. */ | |
1437 | if (!BLOCK_SHOULD_SORT (b)) | |
1438 | sort_block_syms (b); | |
1439 | for (j = 0; j < BLOCK_NSYMS (b); j++) | |
1440 | { | |
1441 | sym = BLOCK_SYM (b, j); | |
1442 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
1443 | { | |
1444 | ||
1445 | char *name = cplus_demangle (SYMBOL_NAME(sym), 0); | |
1446 | if (name) | |
1447 | { | |
1448 | funcVals[0] = Tcl_NewStringObj(name, -1); | |
1449 | funcVals[1] = mangled; | |
1450 | } | |
1451 | else | |
1452 | { | |
1453 | funcVals[0] = Tcl_NewStringObj(SYMBOL_NAME(sym), -1); | |
1454 | funcVals[1] = not_mangled; | |
1455 | } | |
1456 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
1457 | Tcl_NewListObj (2, funcVals)); | |
1458 | } | |
1459 | } | |
1460 | } | |
1461 | return TCL_OK; | |
1462 | } | |
1463 | ||
1464 | \f | |
1465 | /* | |
1466 | * This section contains all the commands that act on the registers: | |
1467 | */ | |
1468 | ||
1469 | /* This is a sort of mapcar function for operations on registers */ | |
1470 | ||
1471 | static int | |
1472 | map_arg_registers (objc, objv, func, argp) | |
1473 | int objc; | |
1474 | Tcl_Obj *CONST objv[]; | |
1475 | void (*func) PARAMS ((int regnum, void *argp)); | |
1476 | void *argp; | |
1477 | { | |
1478 | int regnum; | |
1479 | ||
1480 | /* Note that the test for a valid register must include checking the | |
1481 | reg_names array because NUM_REGS may be allocated for the union of the | |
1482 | register sets within a family of related processors. In this case, the | |
1483 | trailing entries of reg_names will change depending upon the particular | |
1484 | processor being debugged. */ | |
1485 | ||
1486 | if (objc == 0) /* No args, just do all the regs */ | |
1487 | { | |
1488 | for (regnum = 0; | |
1489 | regnum < NUM_REGS | |
1490 | && reg_names[regnum] != NULL | |
1491 | && *reg_names[regnum] != '\000'; | |
1492 | regnum++) | |
1493 | func (regnum, argp); | |
1494 | ||
1495 | return TCL_OK; | |
1496 | } | |
1497 | ||
1498 | /* Else, list of register #s, just do listed regs */ | |
1499 | for (; objc > 0; objc--, objv++) | |
1500 | { | |
1501 | ||
1502 | if (Tcl_GetIntFromObj (NULL, *objv, ®num) != TCL_OK) { | |
1503 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1504 | return TCL_ERROR; | |
1505 | } | |
1506 | ||
1507 | if (regnum >= 0 | |
1508 | && regnum < NUM_REGS | |
1509 | && reg_names[regnum] != NULL | |
1510 | && *reg_names[regnum] != '\000') | |
1511 | func (regnum, argp); | |
1512 | else | |
1513 | { | |
1514 | Tcl_SetStringObj (result_ptr->obj_ptr, "bad register number", -1); | |
1515 | return TCL_ERROR; | |
1516 | } | |
1517 | } | |
1518 | ||
1519 | return TCL_OK; | |
1520 | } | |
1521 | ||
1522 | /* This implements the TCL command `gdb_regnames', which returns a list of | |
1523 | all of the register names. */ | |
1524 | ||
1525 | static int | |
1526 | gdb_regnames (clientData, interp, objc, objv) | |
1527 | ClientData clientData; | |
1528 | Tcl_Interp *interp; | |
1529 | int objc; | |
1530 | Tcl_Obj *CONST objv[]; | |
1531 | { | |
1532 | objc--; | |
1533 | objv++; | |
1534 | ||
1535 | return map_arg_registers (objc, objv, get_register_name, NULL); | |
1536 | } | |
1537 | ||
1538 | static void | |
1539 | get_register_name (regnum, argp) | |
1540 | int regnum; | |
1541 | void *argp; /* Ignored */ | |
1542 | { | |
1543 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
1544 | Tcl_NewStringObj (reg_names[regnum], -1)); | |
1545 | } | |
1546 | ||
1547 | /* This implements the tcl command gdb_fetch_registers | |
1548 | * Pass it a list of register names, and it will | |
1549 | * return their values as a list. | |
1550 | * | |
1551 | * Tcl Arguments: | |
1552 | * format: The format string for printing the values | |
1553 | * args: the registers to look for | |
1554 | * Tcl Result: | |
1555 | * A list of their values. | |
1556 | */ | |
1557 | ||
1558 | static int | |
1559 | gdb_fetch_registers (clientData, interp, objc, objv) | |
1560 | ClientData clientData; | |
1561 | Tcl_Interp *interp; | |
1562 | int objc; | |
1563 | Tcl_Obj *CONST objv[]; | |
1564 | { | |
1565 | int format, result; | |
1566 | ||
1567 | if (objc < 2) | |
1568 | { | |
1569 | Tcl_SetStringObj (result_ptr->obj_ptr, | |
1570 | "wrong # args, should be gdb_fetch_registers format ?register1 register2 ...?", -1); | |
1571 | } | |
1572 | objc -= 2; | |
1573 | objv++; | |
1574 | format = *(Tcl_GetStringFromObj(objv[0], NULL)); | |
1575 | objv++; | |
1576 | ||
1577 | ||
1578 | result_ptr->flags |= GDBTK_MAKES_LIST; /* Output the results as a list */ | |
1579 | result = map_arg_registers (objc, objv, get_register, (void *) format); | |
1580 | result_ptr->flags &= ~GDBTK_MAKES_LIST; | |
1581 | ||
1582 | return result; | |
1583 | } | |
1584 | ||
1585 | static void | |
1586 | get_register (regnum, fp) | |
1587 | int regnum; | |
1588 | void *fp; | |
1589 | { | |
1590 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
1591 | char virtual_buffer[MAX_REGISTER_VIRTUAL_SIZE]; | |
1592 | int format = (int)fp; | |
1593 | ||
1594 | if (format == 'N') | |
1595 | format = 0; | |
1596 | ||
1597 | if (read_relative_register_raw_bytes (regnum, raw_buffer)) | |
1598 | { | |
1599 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
1600 | Tcl_NewStringObj ("Optimized out", -1)); | |
1601 | return; | |
1602 | } | |
1603 | ||
1604 | /* Convert raw data to virtual format if necessary. */ | |
1605 | ||
1606 | if (REGISTER_CONVERTIBLE (regnum)) | |
1607 | { | |
1608 | REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum), | |
1609 | raw_buffer, virtual_buffer); | |
1610 | } | |
1611 | else | |
1612 | memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum)); | |
1613 | ||
1614 | if (format == 'r') | |
1615 | { | |
1616 | int j; | |
1617 | printf_filtered ("0x"); | |
1618 | for (j = 0; j < REGISTER_RAW_SIZE (regnum); j++) | |
1619 | { | |
1620 | register int idx = TARGET_BYTE_ORDER == BIG_ENDIAN ? j | |
1621 | : REGISTER_RAW_SIZE (regnum) - 1 - j; | |
1622 | printf_filtered ("%02x", (unsigned char)raw_buffer[idx]); | |
1623 | } | |
1624 | } | |
1625 | else | |
1626 | val_print (REGISTER_VIRTUAL_TYPE (regnum), virtual_buffer, 0, | |
1627 | gdb_stdout, format, 1, 0, Val_pretty_default); | |
1628 | ||
1629 | } | |
1630 | ||
1631 | /* This implements the tcl command get_pc_reg | |
1632 | * It returns the value of the PC register | |
1633 | * | |
1634 | * Tcl Arguments: | |
1635 | * None | |
1636 | * Tcl Result: | |
1637 | * The value of the pc register. | |
1638 | */ | |
1639 | ||
1640 | static int | |
1641 | get_pc_register (clientData, interp, objc, objv) | |
1642 | ClientData clientData; | |
1643 | Tcl_Interp *interp; | |
1644 | int objc; | |
1645 | Tcl_Obj *CONST objv[]; | |
1646 | { | |
1647 | char buff[64]; | |
1648 | ||
1649 | sprintf (buff, "0x%llx",(long long) read_register (PC_REGNUM)); | |
1650 | Tcl_SetStringObj(result_ptr->obj_ptr, buff, -1); | |
1651 | return TCL_OK; | |
1652 | } | |
1653 | ||
1654 | /* This implements the tcl command "gdb_changed_register_list" | |
1655 | * It takes a list of registers, and returns a list of | |
1656 | * the registers on that list that have changed since the last | |
1657 | * time the proc was called. | |
1658 | * | |
1659 | * Tcl Arguments: | |
1660 | * A list of registers. | |
1661 | * Tcl Result: | |
1662 | * A list of changed registers. | |
1663 | */ | |
1664 | ||
1665 | static int | |
1666 | gdb_changed_register_list (clientData, interp, objc, objv) | |
1667 | ClientData clientData; | |
1668 | Tcl_Interp *interp; | |
1669 | int objc; | |
1670 | Tcl_Obj *CONST objv[]; | |
1671 | { | |
1672 | objc--; | |
1673 | objv++; | |
1674 | ||
1675 | return map_arg_registers (objc, objv, register_changed_p, NULL); | |
1676 | } | |
1677 | ||
1678 | static void | |
1679 | register_changed_p (regnum, argp) | |
1680 | int regnum; | |
1681 | void *argp; /* Ignored */ | |
1682 | { | |
1683 | char raw_buffer[MAX_REGISTER_RAW_SIZE]; | |
1684 | ||
1685 | if (read_relative_register_raw_bytes (regnum, raw_buffer)) | |
1686 | return; | |
1687 | ||
1688 | if (memcmp (&old_regs[REGISTER_BYTE (regnum)], raw_buffer, | |
1689 | REGISTER_RAW_SIZE (regnum)) == 0) | |
1690 | return; | |
1691 | ||
1692 | /* Found a changed register. Save new value and return its number. */ | |
1693 | ||
1694 | memcpy (&old_regs[REGISTER_BYTE (regnum)], raw_buffer, | |
1695 | REGISTER_RAW_SIZE (regnum)); | |
1696 | ||
1697 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj(regnum)); | |
1698 | } | |
1699 | \f | |
1700 | /* | |
1701 | * This section contains the commands that deal with tracepoints: | |
1702 | */ | |
1703 | ||
1704 | /* return a list of all tracepoint numbers in interpreter */ | |
1705 | static int | |
1706 | gdb_get_tracepoint_list (clientData, interp, objc, objv) | |
1707 | ClientData clientData; | |
1708 | Tcl_Interp *interp; | |
1709 | int objc; | |
1710 | Tcl_Obj *CONST objv[]; | |
1711 | { | |
1712 | struct tracepoint *tp; | |
1713 | ||
1714 | Tcl_SetListObj (result_ptr->obj_ptr, 0, NULL); | |
1715 | ||
1716 | ALL_TRACEPOINTS (tp) | |
1717 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->number)); | |
1718 | ||
1719 | return TCL_OK; | |
1720 | } | |
1721 | ||
1722 | /* returns -1 if not found, tracepoint # if found */ | |
1723 | int | |
1724 | tracepoint_exists (char * args) | |
1725 | { | |
1726 | struct tracepoint *tp; | |
1727 | char **canonical; | |
1728 | struct symtabs_and_lines sals; | |
1729 | char *file = NULL; | |
1730 | int result = -1; | |
1731 | ||
1732 | sals = decode_line_1 (&args, 1, NULL, 0, &canonical); | |
1733 | if (sals.nelts == 1) | |
1734 | { | |
1735 | resolve_sal_pc (&sals.sals[0]); | |
1736 | file = xmalloc (strlen (sals.sals[0].symtab->dirname) | |
1737 | + strlen (sals.sals[0].symtab->filename) + 1); | |
1738 | if (file != NULL) | |
1739 | { | |
1740 | strcpy (file, sals.sals[0].symtab->dirname); | |
1741 | strcat (file, sals.sals[0].symtab->filename); | |
1742 | ||
1743 | ALL_TRACEPOINTS (tp) | |
1744 | { | |
1745 | if (tp->address == sals.sals[0].pc) | |
1746 | result = tp->number; | |
1747 | #if 0 | |
1748 | /* Why is this here? This messes up assembly traces */ | |
1749 | else if (tp->source_file != NULL | |
1750 | && strcmp (tp->source_file, file) == 0 | |
1751 | && sals.sals[0].line == tp->line_number) | |
1752 | result = tp->number; | |
1753 | #endif | |
1754 | } | |
1755 | } | |
1756 | } | |
1757 | if (file != NULL) | |
1758 | free (file); | |
1759 | return result; | |
1760 | } | |
1761 | ||
1762 | static int | |
1763 | gdb_tracepoint_exists_command (clientData, interp, objc, objv) | |
1764 | ClientData clientData; | |
1765 | Tcl_Interp *interp; | |
1766 | int objc; | |
1767 | Tcl_Obj *CONST objv[]; | |
1768 | { | |
1769 | char * args; | |
1770 | ||
1771 | if (objc != 2) | |
1772 | { | |
1773 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # of args: should be \"", | |
1774 | Tcl_GetStringFromObj (objv[0], NULL), | |
1775 | " function:line|function|line|*addr\"", NULL); | |
1776 | return TCL_ERROR; | |
1777 | } | |
1778 | ||
1779 | args = Tcl_GetStringFromObj (objv[1], NULL); | |
1780 | ||
1781 | Tcl_SetIntObj (result_ptr->obj_ptr, tracepoint_exists (args)); | |
1782 | return TCL_OK; | |
1783 | } | |
1784 | ||
1785 | static int | |
1786 | gdb_get_tracepoint_info (clientData, interp, objc, objv) | |
1787 | ClientData clientData; | |
1788 | Tcl_Interp *interp; | |
1789 | int objc; | |
1790 | Tcl_Obj *CONST objv[]; | |
1791 | { | |
1792 | struct symtab_and_line sal; | |
1793 | int tpnum; | |
1794 | struct tracepoint *tp; | |
1795 | struct action_line *al; | |
1796 | Tcl_Obj *action_list; | |
1797 | char *filename, *funcname; | |
1798 | char tmp[19]; | |
1799 | ||
1800 | if (objc != 2) | |
1801 | { | |
1802 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong # args", -1); | |
1803 | return TCL_ERROR; | |
1804 | } | |
1805 | ||
1806 | if (Tcl_GetIntFromObj (NULL, objv[1], &tpnum) != TCL_OK) | |
1807 | { | |
1808 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
1809 | return TCL_ERROR; | |
1810 | } | |
1811 | ||
1812 | ALL_TRACEPOINTS (tp) | |
1813 | if (tp->number == tpnum) | |
1814 | break; | |
1815 | ||
1816 | if (tp == NULL) | |
1817 | { | |
1818 | Tcl_SetStringObj (result_ptr->obj_ptr, "Tracepoint #%d does not exist", -1); | |
1819 | return TCL_ERROR; | |
1820 | } | |
1821 | ||
1822 | Tcl_SetListObj (result_ptr->obj_ptr, 0, NULL); | |
1823 | sal = find_pc_line (tp->address, 0); | |
1824 | filename = symtab_to_filename (sal.symtab); | |
1825 | if (filename == NULL) | |
1826 | filename = "N/A"; | |
1827 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, | |
1828 | Tcl_NewStringObj (filename, -1)); | |
1829 | find_pc_partial_function (tp->address, &funcname, NULL, NULL); | |
1830 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewStringObj (funcname, -1)); | |
1831 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (sal.line)); | |
1832 | sprintf (tmp, "0x%lx", tp->address); | |
1833 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewStringObj (tmp, -1)); | |
1834 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->enabled)); | |
1835 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->pass_count)); | |
1836 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->step_count)); | |
1837 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->thread)); | |
1838 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, Tcl_NewIntObj (tp->hit_count)); | |
1839 | ||
1840 | /* Append a list of actions */ | |
1841 | action_list = Tcl_NewObj (); | |
1842 | for (al = tp->actions; al != NULL; al = al->next) | |
1843 | { | |
1844 | Tcl_ListObjAppendElement (interp, action_list, | |
1845 | Tcl_NewStringObj (al->action, -1)); | |
1846 | } | |
1847 | Tcl_ListObjAppendElement (interp, result_ptr->obj_ptr, action_list); | |
1848 | ||
1849 | return TCL_OK; | |
1850 | } | |
1851 | ||
1852 | ||
1853 | static int | |
1854 | gdb_trace_status (clientData, interp, objc, objv) | |
1855 | ClientData clientData; | |
1856 | Tcl_Interp *interp; | |
1857 | int objc; | |
1858 | Tcl_Obj *CONST objv[]; | |
1859 | { | |
1860 | int result = 0; | |
1861 | ||
1862 | if (trace_running_p) | |
1863 | result = 1; | |
1864 | ||
1865 | Tcl_SetIntObj (result_ptr->obj_ptr, result); | |
1866 | return TCL_OK; | |
1867 | } | |
1868 | ||
1869 | ||
1870 | ||
1871 | static int | |
1872 | gdb_get_trace_frame_num (clientData, interp, objc, objv) | |
1873 | ClientData clientData; | |
1874 | Tcl_Interp *interp; | |
1875 | int objc; | |
1876 | Tcl_Obj *CONST objv[]; | |
1877 | { | |
1878 | if (objc != 1) | |
1879 | { | |
1880 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # of args: should be \"", | |
1881 | Tcl_GetStringFromObj (objv[0], NULL), | |
1882 | " linespec\"", NULL); | |
1883 | return TCL_ERROR; | |
1884 | } | |
1885 | ||
1886 | Tcl_SetIntObj (result_ptr->obj_ptr, get_traceframe_number ()); | |
1887 | return TCL_OK; | |
1888 | ||
1889 | } | |
1890 | ||
1891 | /* This implements the tcl command gdb_actions | |
1892 | * It sets actions for a given tracepoint. | |
1893 | * | |
1894 | * Tcl Arguments: | |
1895 | * number: the tracepoint in question | |
1896 | * actions: the actions to add to this tracepoint | |
1897 | * Tcl Result: | |
1898 | * None. | |
1899 | */ | |
1900 | ||
1901 | static int | |
1902 | gdb_actions_command (clientData, interp, objc, objv) | |
1903 | ClientData clientData; | |
1904 | Tcl_Interp *interp; | |
1905 | int objc; | |
1906 | Tcl_Obj *CONST objv[]; | |
1907 | { | |
1908 | struct tracepoint *tp; | |
1909 | Tcl_Obj **actions; | |
1910 | int nactions, i, len; | |
1911 | char *number, *args, *action; | |
1912 | long step_count; | |
1913 | struct action_line *next = NULL, *temp; | |
1914 | enum actionline_type linetype; | |
1915 | ||
1916 | if (objc != 3) | |
1917 | { | |
1918 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "wrong # args: should be: \"", | |
1919 | Tcl_GetStringFromObj (objv[0], NULL), | |
1920 | " number actions\"", NULL); | |
1921 | return TCL_ERROR; | |
1922 | } | |
1923 | ||
1924 | args = number = Tcl_GetStringFromObj (objv[1], NULL); | |
1925 | tp = get_tracepoint_by_number (&args); | |
1926 | if (tp == NULL) | |
1927 | { | |
1928 | Tcl_AppendStringsToObj (result_ptr->obj_ptr, "Tracepoint \"", number, "\" does not exist", NULL); | |
1929 | return TCL_ERROR; | |
1930 | } | |
1931 | ||
1932 | /* Free any existing actions */ | |
1933 | if (tp->actions != NULL) | |
1934 | free_actions (tp); | |
1935 | ||
1936 | step_count = 0; | |
1937 | ||
1938 | Tcl_ListObjGetElements (interp, objv[2], &nactions, &actions); | |
1939 | ||
1940 | /* Add the actions to the tracepoint */ | |
1941 | for (i = 0; i < nactions; i++) | |
1942 | { | |
1943 | temp = xmalloc (sizeof (struct action_line)); | |
1944 | temp->next = NULL; | |
1945 | action = Tcl_GetStringFromObj (actions[i], &len); | |
1946 | temp->action = savestring (action, len); | |
1947 | ||
1948 | linetype = validate_actionline (&(temp->action), tp); | |
1949 | ||
1950 | if (linetype == BADLINE) | |
1951 | { | |
1952 | free (temp); | |
1953 | continue; | |
1954 | } | |
1955 | ||
1956 | if (next == NULL) | |
1957 | { | |
1958 | tp->actions = temp; | |
1959 | next = temp; | |
1960 | } | |
1961 | else | |
1962 | { | |
1963 | next->next = temp; | |
1964 | next = temp; | |
1965 | } | |
1966 | } | |
1967 | ||
1968 | return TCL_OK; | |
1969 | } | |
1970 | \f | |
1971 | /* | |
1972 | * This section has commands that handle source disassembly. | |
1973 | */ | |
1974 | ||
1975 | /* This implements the tcl command gdb_disassemble | |
1976 | * | |
1977 | * Arguments: | |
1978 | * source_with_assm - must be "source" or "nosource" | |
1979 | * low_address - the address from which to start disassembly | |
1980 | * ?hi_address? - the address to which to disassemble, defaults | |
1981 | * to the end of the function containing low_address. | |
1982 | * Tcl Result: | |
1983 | * The disassembled code is passed to fputs_unfiltered, so it | |
1984 | * either goes to the console if result_ptr->obj_ptr is NULL or to | |
1985 | * the Tcl result. | |
1986 | */ | |
1987 | ||
1988 | static int | |
1989 | gdb_disassemble (clientData, interp, objc, objv) | |
1990 | ClientData clientData; | |
1991 | Tcl_Interp *interp; | |
1992 | int objc; | |
1993 | Tcl_Obj *CONST objv[]; | |
1994 | { | |
1995 | CORE_ADDR pc, low, high; | |
1996 | int mixed_source_and_assembly; | |
1997 | static disassemble_info di; | |
1998 | static int di_initialized; | |
1999 | char *arg_ptr; | |
2000 | ||
2001 | if (objc != 3 && objc != 4) | |
2002 | error ("wrong # args"); | |
2003 | ||
2004 | if (! di_initialized) | |
2005 | { | |
2006 | INIT_DISASSEMBLE_INFO_NO_ARCH (di, gdb_stdout, | |
2007 | (fprintf_ftype) fprintf_unfiltered); | |
2008 | di.flavour = bfd_target_unknown_flavour; | |
2009 | di.memory_error_func = dis_asm_memory_error; | |
2010 | di.print_address_func = dis_asm_print_address; | |
2011 | di_initialized = 1; | |
2012 | } | |
2013 | ||
2014 | di.mach = tm_print_insn_info.mach; | |
2015 | if (TARGET_BYTE_ORDER == BIG_ENDIAN) | |
2016 | di.endian = BFD_ENDIAN_BIG; | |
2017 | else | |
2018 | di.endian = BFD_ENDIAN_LITTLE; | |
2019 | ||
2020 | arg_ptr = Tcl_GetStringFromObj (objv[1], NULL); | |
2021 | if (*arg_ptr == 's' && strcmp (arg_ptr, "source") == 0) | |
2022 | mixed_source_and_assembly = 1; | |
2023 | else if (*arg_ptr == 'n' && strcmp (arg_ptr, "nosource") == 0) | |
2024 | mixed_source_and_assembly = 0; | |
2025 | else | |
2026 | error ("First arg must be 'source' or 'nosource'"); | |
2027 | ||
2028 | low = parse_and_eval_address (Tcl_GetStringFromObj (objv[2], NULL)); | |
2029 | ||
2030 | if (objc == 3) | |
2031 | { | |
2032 | if (find_pc_partial_function (low, NULL, &low, &high) == 0) | |
2033 | error ("No function contains specified address"); | |
2034 | } | |
2035 | else | |
2036 | high = parse_and_eval_address (Tcl_GetStringFromObj (objv[3], NULL)); | |
2037 | ||
2038 | /* If disassemble_from_exec == -1, then we use the following heuristic to | |
2039 | determine whether or not to do disassembly from target memory or from the | |
2040 | exec file: | |
2041 | ||
2042 | If we're debugging a local process, read target memory, instead of the | |
2043 | exec file. This makes disassembly of functions in shared libs work | |
2044 | correctly. | |
2045 | ||
2046 | Else, we're debugging a remote process, and should disassemble from the | |
2047 | exec file for speed. However, this is no good if the target modifies its | |
2048 | code (for relocation, or whatever). | |
2049 | */ | |
2050 | ||
2051 | if (disassemble_from_exec == -1) | |
2052 | if (strcmp (target_shortname, "child") == 0 | |
2053 | || strcmp (target_shortname, "procfs") == 0 | |
2054 | || strcmp (target_shortname, "vxprocess") == 0) | |
2055 | disassemble_from_exec = 0; /* It's a child process, read inferior mem */ | |
2056 | else | |
2057 | disassemble_from_exec = 1; /* It's remote, read the exec file */ | |
2058 | ||
2059 | if (disassemble_from_exec) | |
2060 | di.read_memory_func = gdbtk_dis_asm_read_memory; | |
2061 | else | |
2062 | di.read_memory_func = dis_asm_read_memory; | |
2063 | ||
2064 | /* If just doing straight assembly, all we need to do is disassemble | |
2065 | everything between low and high. If doing mixed source/assembly, we've | |
2066 | got a totally different path to follow. */ | |
2067 | ||
2068 | if (mixed_source_and_assembly) | |
2069 | { /* Come here for mixed source/assembly */ | |
2070 | /* The idea here is to present a source-O-centric view of a function to | |
2071 | the user. This means that things are presented in source order, with | |
2072 | (possibly) out of order assembly immediately following. */ | |
2073 | struct symtab *symtab; | |
2074 | struct linetable_entry *le; | |
2075 | int nlines; | |
2076 | int newlines; | |
2077 | struct my_line_entry *mle; | |
2078 | struct symtab_and_line sal; | |
2079 | int i; | |
2080 | int out_of_order; | |
2081 | int next_line; | |
2082 | ||
2083 | symtab = find_pc_symtab (low); /* Assume symtab is valid for whole PC range */ | |
2084 | ||
2085 | if (!symtab) | |
2086 | goto assembly_only; | |
2087 | ||
2088 | /* First, convert the linetable to a bunch of my_line_entry's. */ | |
2089 | ||
2090 | le = symtab->linetable->item; | |
2091 | nlines = symtab->linetable->nitems; | |
2092 | ||
2093 | if (nlines <= 0) | |
2094 | goto assembly_only; | |
2095 | ||
2096 | mle = (struct my_line_entry *) alloca (nlines * sizeof (struct my_line_entry)); | |
2097 | ||
2098 | out_of_order = 0; | |
2099 | ||
2100 | /* Copy linetable entries for this function into our data structure, creating | |
2101 | end_pc's and setting out_of_order as appropriate. */ | |
2102 | ||
2103 | /* First, skip all the preceding functions. */ | |
2104 | ||
2105 | for (i = 0; i < nlines - 1 && le[i].pc < low; i++) ; | |
2106 | ||
2107 | /* Now, copy all entries before the end of this function. */ | |
2108 | ||
2109 | newlines = 0; | |
2110 | for (; i < nlines - 1 && le[i].pc < high; i++) | |
2111 | { | |
2112 | if (le[i].line == le[i + 1].line | |
2113 | && le[i].pc == le[i + 1].pc) | |
2114 | continue; /* Ignore duplicates */ | |
2115 | ||
2116 | mle[newlines].line = le[i].line; | |
2117 | if (le[i].line > le[i + 1].line) | |
2118 | out_of_order = 1; | |
2119 | mle[newlines].start_pc = le[i].pc; | |
2120 | mle[newlines].end_pc = le[i + 1].pc; | |
2121 | newlines++; | |
2122 | } | |
2123 | ||
2124 | /* If we're on the last line, and it's part of the function, then we need to | |
2125 | get the end pc in a special way. */ | |
2126 | ||
2127 | if (i == nlines - 1 | |
2128 | && le[i].pc < high) | |
2129 | { | |
2130 | mle[newlines].line = le[i].line; | |
2131 | mle[newlines].start_pc = le[i].pc; | |
2132 | sal = find_pc_line (le[i].pc, 0); | |
2133 | mle[newlines].end_pc = sal.end; | |
2134 | newlines++; | |
2135 | } | |
2136 | ||
2137 | /* Now, sort mle by line #s (and, then by addresses within lines). */ | |
2138 | ||
2139 | if (out_of_order) | |
2140 | qsort (mle, newlines, sizeof (struct my_line_entry), compare_lines); | |
2141 | ||
2142 | /* Now, for each line entry, emit the specified lines (unless they have been | |
2143 | emitted before), followed by the assembly code for that line. */ | |
2144 | ||
2145 | next_line = 0; /* Force out first line */ | |
2146 | for (i = 0; i < newlines; i++) | |
2147 | { | |
2148 | /* Print out everything from next_line to the current line. */ | |
2149 | ||
2150 | if (mle[i].line >= next_line) | |
2151 | { | |
2152 | if (next_line != 0) | |
2153 | print_source_lines (symtab, next_line, mle[i].line + 1, 0); | |
2154 | else | |
2155 | print_source_lines (symtab, mle[i].line, mle[i].line + 1, 0); | |
2156 | ||
2157 | next_line = mle[i].line + 1; | |
2158 | } | |
2159 | ||
2160 | for (pc = mle[i].start_pc; pc < mle[i].end_pc; ) | |
2161 | { | |
2162 | QUIT; | |
2163 | fputs_unfiltered (" ", gdb_stdout); | |
2164 | print_address (pc, gdb_stdout); | |
2165 | fputs_unfiltered (":\t ", gdb_stdout); | |
2166 | pc += (*tm_print_insn) (pc, &di); | |
2167 | fputs_unfiltered ("\n", gdb_stdout); | |
2168 | } | |
2169 | } | |
2170 | } | |
2171 | else | |
2172 | { | |
2173 | assembly_only: | |
2174 | for (pc = low; pc < high; ) | |
2175 | { | |
2176 | QUIT; | |
2177 | fputs_unfiltered (" ", gdb_stdout); | |
2178 | print_address (pc, gdb_stdout); | |
2179 | fputs_unfiltered (":\t ", gdb_stdout); | |
2180 | pc += (*tm_print_insn) (pc, &di); | |
2181 | fputs_unfiltered ("\n", gdb_stdout); | |
2182 | } | |
2183 | } | |
2184 | ||
2185 | gdb_flush (gdb_stdout); | |
2186 | ||
2187 | return TCL_OK; | |
2188 | } | |
2189 | ||
2190 | /* This is the memory_read_func for gdb_disassemble when we are | |
2191 | disassembling from the exec file. */ | |
2192 | ||
2193 | static int | |
2194 | gdbtk_dis_asm_read_memory (memaddr, myaddr, len, info) | |
2195 | bfd_vma memaddr; | |
2196 | bfd_byte *myaddr; | |
2197 | int len; | |
2198 | disassemble_info *info; | |
2199 | { | |
2200 | extern struct target_ops exec_ops; | |
2201 | int res; | |
2202 | ||
2203 | errno = 0; | |
2204 | res = xfer_memory (memaddr, myaddr, len, 0, &exec_ops); | |
2205 | ||
2206 | if (res == len) | |
2207 | return 0; | |
2208 | else | |
2209 | if (errno == 0) | |
2210 | return EIO; | |
2211 | else | |
2212 | return errno; | |
2213 | } | |
2214 | ||
2215 | /* This will be passed to qsort to sort the results of the disassembly */ | |
2216 | ||
2217 | static int | |
2218 | compare_lines (mle1p, mle2p) | |
2219 | const PTR mle1p; | |
2220 | const PTR mle2p; | |
2221 | { | |
2222 | struct my_line_entry *mle1, *mle2; | |
2223 | int val; | |
2224 | ||
2225 | mle1 = (struct my_line_entry *) mle1p; | |
2226 | mle2 = (struct my_line_entry *) mle2p; | |
2227 | ||
2228 | val = mle1->line - mle2->line; | |
2229 | ||
2230 | if (val != 0) | |
2231 | return val; | |
2232 | ||
2233 | return mle1->start_pc - mle2->start_pc; | |
2234 | } | |
2235 | ||
2236 | /* This implements the TCL command `gdb_loc', | |
2237 | * | |
2238 | * Arguments: | |
2239 | * ?symbol? The symbol or address to locate - defaults to pc | |
2240 | * Tcl Return: | |
2241 | * a list consisting of the following: | |
2242 | * basename, function name, filename, line number, address, current pc | |
2243 | */ | |
2244 | ||
2245 | static int | |
2246 | gdb_loc (clientData, interp, objc, objv) | |
2247 | ClientData clientData; | |
2248 | Tcl_Interp *interp; | |
2249 | int objc; | |
2250 | Tcl_Obj *CONST objv[]; | |
2251 | { | |
2252 | char *filename; | |
2253 | struct symtab_and_line sal; | |
2254 | char *funcname, *fname; | |
2255 | CORE_ADDR pc; | |
2256 | ||
2257 | if (!have_full_symbols () && !have_partial_symbols ()) | |
2258 | { | |
2259 | Tcl_SetStringObj (result_ptr->obj_ptr, "No symbol table is loaded", -1); | |
2260 | return TCL_ERROR; | |
2261 | } | |
2262 | ||
2263 | if (objc == 1) | |
2264 | { | |
2265 | if (selected_frame && (selected_frame->pc != stop_pc)) | |
2266 | { | |
2267 | /* Note - this next line is not correct on all architectures. */ | |
2268 | /* For a graphical debugger we really want to highlight the */ | |
2269 | /* assembly line that called the next function on the stack. */ | |
2270 | /* Many architectures have the next instruction saved as the */ | |
2271 | /* pc on the stack, so what happens is the next instruction is hughlighted. */ | |
2272 | /* FIXME */ | |
2273 | pc = selected_frame->pc; | |
2274 | sal = find_pc_line (selected_frame->pc, | |
2275 | selected_frame->next != NULL | |
2276 | && !selected_frame->next->signal_handler_caller | |
2277 | && !frame_in_dummy (selected_frame->next)); | |
2278 | } | |
2279 | else | |
2280 | { | |
2281 | pc = stop_pc; | |
2282 | sal = find_pc_line (stop_pc, 0); | |
2283 | } | |
2284 | } | |
2285 | else if (objc == 2) | |
2286 | { | |
2287 | struct symtabs_and_lines sals; | |
2288 | int nelts; | |
2289 | ||
2290 | sals = decode_line_spec (Tcl_GetStringFromObj (objv[1], NULL), 1); | |
2291 | ||
2292 | nelts = sals.nelts; | |
2293 | sal = sals.sals[0]; | |
2294 | free (sals.sals); | |
2295 | ||
2296 | if (sals.nelts != 1) | |
2297 | { | |
2298 | Tcl_SetStringObj (result_ptr->obj_ptr, "Ambiguous line spec", -1); | |
2299 | return TCL_ERROR; | |
2300 | } | |
2301 | ||
2302 | pc = sal.pc; | |
2303 | } | |
2304 | else | |
2305 | { | |
2306 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong # args", -1); | |
2307 | return TCL_ERROR; | |
2308 | } | |
2309 | ||
2310 | if (sal.symtab) | |
2311 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2312 | Tcl_NewStringObj (sal.symtab->filename, -1)); | |
2313 | else | |
2314 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewStringObj ("", 0)); | |
2315 | ||
2316 | find_pc_partial_function (pc, &funcname, NULL, NULL); | |
2317 | fname = cplus_demangle (funcname, 0); | |
2318 | if (fname) | |
2319 | { | |
2320 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2321 | Tcl_NewStringObj (fname, -1)); | |
2322 | free (fname); | |
2323 | } | |
2324 | else | |
2325 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2326 | Tcl_NewStringObj (funcname, -1)); | |
2327 | ||
2328 | filename = symtab_to_filename (sal.symtab); | |
2329 | if (filename == NULL) | |
2330 | filename = ""; | |
2331 | ||
2332 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2333 | Tcl_NewStringObj (filename, -1)); | |
2334 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj(sal.line)); /* line number */ | |
2335 | sprintf_append_element_to_obj (result_ptr->obj_ptr, "0x%s", paddr_nz(pc)); /* PC in current frame */ | |
2336 | sprintf_append_element_to_obj (result_ptr->obj_ptr, "0x%s", paddr_nz(stop_pc)); /* Real PC */ | |
2337 | return TCL_OK; | |
2338 | } | |
2339 | ||
2340 | /* This implements the Tcl command 'gdb_get_mem', which | |
2341 | * dumps a block of memory | |
2342 | * Arguments: | |
2343 | * gdb_get_mem addr form size num aschar | |
2344 | * | |
2345 | * addr: address of data to dump | |
2346 | * form: a char indicating format | |
2347 | * size: size of each element; 1,2,4, or 8 bytes | |
2348 | * num: the number of bytes to read | |
2349 | * acshar: an optional ascii character to use in ASCII dump | |
2350 | * | |
2351 | * Return: | |
2352 | * a list of elements followed by an optional ASCII dump | |
2353 | */ | |
2354 | ||
2355 | static int | |
2356 | gdb_get_mem (clientData, interp, objc, objv) | |
2357 | ClientData clientData; | |
2358 | Tcl_Interp *interp; | |
2359 | int objc; | |
2360 | Tcl_Obj *CONST objv[]; | |
2361 | { | |
2362 | int size, asize, i, j, bc; | |
2363 | CORE_ADDR addr; | |
2364 | int nbytes, rnum, bpr; | |
2365 | long tmp; | |
2366 | char format, c, *ptr, buff[128], aschar, *mbuf, *mptr, *cptr, *bptr; | |
2367 | struct type *val_type; | |
2368 | ||
2369 | if (objc < 6 || objc > 7) | |
2370 | { | |
2371 | Tcl_SetStringObj (result_ptr->obj_ptr, | |
2372 | "addr format size bytes bytes_per_row ?ascii_char?", -1); | |
2373 | return TCL_ERROR; | |
2374 | } | |
2375 | ||
2376 | if (Tcl_GetIntFromObj (interp, objv[3], &size) != TCL_OK) | |
2377 | { | |
2378 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
2379 | return TCL_ERROR; | |
2380 | } | |
2381 | else if (size <= 0) | |
2382 | { | |
2383 | Tcl_SetStringObj (result_ptr->obj_ptr, "Invalid size, must be > 0", -1); | |
2384 | return TCL_ERROR; | |
2385 | } | |
2386 | ||
2387 | if (Tcl_GetIntFromObj (interp, objv[4], &nbytes) != TCL_OK) | |
2388 | { | |
2389 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
2390 | return TCL_ERROR; | |
2391 | } | |
2392 | else if (size <= 0) | |
2393 | { | |
2394 | Tcl_SetStringObj (result_ptr->obj_ptr, "Invalid number of bytes, must be > 0", | |
2395 | -1); | |
2396 | return TCL_ERROR; | |
2397 | } | |
2398 | ||
2399 | if (Tcl_GetIntFromObj (interp, objv[5], &bpr) != TCL_OK) | |
2400 | { | |
2401 | result_ptr->flags |= GDBTK_IN_TCL_RESULT; | |
2402 | return TCL_ERROR; | |
2403 | } | |
2404 | else if (size <= 0) | |
2405 | { | |
2406 | Tcl_SetStringObj (result_ptr->obj_ptr, "Invalid bytes per row, must be > 0", -1); | |
2407 | return TCL_ERROR; | |
2408 | } | |
2409 | ||
2410 | if (Tcl_GetLongFromObj (interp, objv[1], &tmp) != TCL_OK) | |
2411 | return TCL_OK; | |
2412 | ||
2413 | addr = (CORE_ADDR) tmp; | |
2414 | ||
2415 | format = *(Tcl_GetStringFromObj (objv[2], NULL)); | |
2416 | mbuf = (char *)malloc (nbytes+32); | |
2417 | if (!mbuf) | |
2418 | { | |
2419 | Tcl_SetStringObj (result_ptr->obj_ptr, "Out of memory.", -1); | |
2420 | return TCL_ERROR; | |
2421 | } | |
2422 | ||
2423 | memset (mbuf, 0, nbytes+32); | |
2424 | mptr = cptr = mbuf; | |
2425 | ||
2426 | rnum = target_read_memory_partial (addr, mbuf, nbytes, NULL); | |
2427 | ||
2428 | if (objc == 7) | |
2429 | aschar = *(Tcl_GetStringFromObj(objv[6], NULL)); | |
2430 | else | |
2431 | aschar = 0; | |
2432 | ||
2433 | switch (size) { | |
2434 | case 1: | |
2435 | val_type = builtin_type_char; | |
2436 | asize = 'b'; | |
2437 | break; | |
2438 | case 2: | |
2439 | val_type = builtin_type_short; | |
2440 | asize = 'h'; | |
2441 | break; | |
2442 | case 4: | |
2443 | val_type = builtin_type_int; | |
2444 | asize = 'w'; | |
2445 | break; | |
2446 | case 8: | |
2447 | val_type = builtin_type_long_long; | |
2448 | asize = 'g'; | |
2449 | break; | |
2450 | default: | |
2451 | val_type = builtin_type_char; | |
2452 | asize = 'b'; | |
2453 | } | |
2454 | ||
2455 | bc = 0; /* count of bytes in a row */ | |
2456 | buff[0] = '"'; /* buffer for ascii dump */ | |
2457 | bptr = &buff[1]; /* pointer for ascii dump */ | |
2458 | ||
2459 | result_ptr->flags |= GDBTK_MAKES_LIST; /* Build up the result as a list... */ | |
2460 | ||
2461 | for (i=0; i < nbytes; i+= size) | |
2462 | { | |
2463 | if ( i >= rnum) | |
2464 | { | |
2465 | fputs_unfiltered ("N/A ", gdb_stdout); | |
2466 | if (aschar) | |
2467 | for ( j = 0; j < size; j++) | |
2468 | *bptr++ = 'X'; | |
2469 | } | |
2470 | else | |
2471 | { | |
2472 | print_scalar_formatted (mptr, val_type, format, asize, gdb_stdout); | |
2473 | ||
2474 | if (aschar) | |
2475 | { | |
2476 | for ( j = 0; j < size; j++) | |
2477 | { | |
2478 | c = *cptr++; | |
2479 | if (c < 32 || c > 126) | |
2480 | c = aschar; | |
2481 | if (c == '"') | |
2482 | *bptr++ = '\\'; | |
2483 | *bptr++ = c; | |
2484 | } | |
2485 | } | |
2486 | } | |
2487 | ||
2488 | mptr += size; | |
2489 | bc += size; | |
2490 | ||
2491 | if (aschar && (bc >= bpr)) | |
2492 | { | |
2493 | /* end of row. print it and reset variables */ | |
2494 | bc = 0; | |
2495 | *bptr++ = '"'; | |
2496 | *bptr++ = ' '; | |
2497 | *bptr = 0; | |
2498 | fputs_unfiltered (buff, gdb_stdout); | |
2499 | bptr = &buff[1]; | |
2500 | } | |
2501 | } | |
2502 | ||
2503 | result_ptr->flags &= ~GDBTK_MAKES_LIST; | |
2504 | ||
2505 | free (mbuf); | |
2506 | return TCL_OK; | |
2507 | } | |
2508 | ||
2509 | \f | |
2510 | ||
2511 | /* This implements the tcl command "gdb_loadfile" | |
2512 | * It loads a c source file into a text widget. | |
2513 | * | |
2514 | * Tcl Arguments: | |
2515 | * widget: the name of the text widget to fill | |
2516 | * filename: the name of the file to load | |
2517 | * linenumbers: A boolean indicating whether or not to display line numbers. | |
2518 | * Tcl Result: | |
2519 | * | |
2520 | */ | |
2521 | ||
2522 | /* In this routine, we will build up a "line table", i.e. a | |
2523 | * table of bits showing which lines in the source file are executible. | |
2524 | * LTABLE_SIZE is the number of bytes to allocate for the line table. | |
2525 | * | |
2526 | * Its size limits the maximum number of lines | |
2527 | * in a file to 8 * LTABLE_SIZE. This memory is freed after | |
2528 | * the file is loaded, so it is OK to make this very large. | |
2529 | * Additional memory will be allocated if needed. */ | |
2530 | #define LTABLE_SIZE 20000 | |
2531 | static int | |
2532 | gdb_loadfile (clientData, interp, objc, objv) | |
2533 | ClientData clientData; | |
2534 | Tcl_Interp *interp; | |
2535 | int objc; | |
2536 | Tcl_Obj *CONST objv[]; | |
2537 | { | |
2538 | char *file, *widget, *buf, msg[128]; | |
2539 | int linenumbers, ln, anum, lnum, ltable_size; | |
2540 | FILE *fp; | |
2541 | char *ltable; | |
2542 | struct symtab *symtab; | |
2543 | struct linetable_entry *le; | |
2544 | long mtime = 0; | |
2545 | struct stat st; | |
2546 | Tcl_DString text_cmd_1, text_cmd_2, *cur_cmd; | |
2547 | char line[1024], line_num_buf[16]; | |
2548 | int prefix_len_1, prefix_len_2, cur_prefix_len, widget_len; | |
2549 | ||
2550 | ||
2551 | if (objc != 4) | |
2552 | { | |
2553 | Tcl_WrongNumArgs(interp, 1, objv, "widget filename linenumbers"); | |
2554 | return TCL_ERROR; | |
2555 | } | |
2556 | ||
2557 | widget = Tcl_GetStringFromObj (objv[1], NULL); | |
2558 | if ( Tk_NameToWindow (interp, widget, Tk_MainWindow (interp)) == NULL) | |
2559 | { | |
2560 | return TCL_ERROR; | |
2561 | } | |
2562 | ||
2563 | file = Tcl_GetStringFromObj (objv[2], NULL); | |
2564 | Tcl_GetBooleanFromObj (interp, objv[3], &linenumbers); | |
2565 | ||
2566 | if ((fp = fopen ( file, "r" )) == NULL) | |
2567 | { | |
2568 | Tcl_SetStringObj ( result_ptr->obj_ptr, "Can't open file for reading", -1); | |
2569 | return TCL_ERROR; | |
2570 | } | |
2571 | ||
2572 | symtab = full_lookup_symtab (file); | |
2573 | if (!symtab) | |
2574 | { | |
2575 | Tcl_SetStringObj ( result_ptr->obj_ptr, "File not found in symtab", -1); | |
2576 | fclose (fp); | |
2577 | return TCL_ERROR; | |
2578 | } | |
2579 | ||
2580 | if (stat (file, &st) < 0) | |
2581 | { | |
2582 | catch_errors (perror_with_name_wrapper, "gdbtk: get time stamp", "", | |
2583 | RETURN_MASK_ALL); | |
2584 | return TCL_ERROR; | |
2585 | } | |
2586 | ||
2587 | if (symtab && symtab->objfile && symtab->objfile->obfd) | |
2588 | mtime = bfd_get_mtime(symtab->objfile->obfd); | |
2589 | else if (exec_bfd) | |
2590 | mtime = bfd_get_mtime(exec_bfd); | |
2591 | ||
2592 | if (mtime && mtime < st.st_mtime) | |
2593 | gdbtk_ignorable_warning("Source file is more recent than executable.\n"); | |
2594 | ||
2595 | ||
2596 | /* Source linenumbers don't appear to be in order, and a sort is */ | |
2597 | /* too slow so the fastest solution is just to allocate a huge */ | |
2598 | /* array and set the array entry for each linenumber */ | |
2599 | ||
2600 | ltable_size = LTABLE_SIZE; | |
2601 | ltable = (char *)malloc (LTABLE_SIZE); | |
2602 | if (ltable == NULL) | |
2603 | { | |
2604 | Tcl_SetStringObj ( result_ptr->obj_ptr, "Out of memory.", -1); | |
2605 | fclose (fp); | |
2606 | return TCL_ERROR; | |
2607 | } | |
2608 | ||
2609 | memset (ltable, 0, LTABLE_SIZE); | |
2610 | ||
2611 | if (symtab->linetable && symtab->linetable->nitems) | |
2612 | { | |
2613 | le = symtab->linetable->item; | |
2614 | for (ln = symtab->linetable->nitems ;ln > 0; ln--, le++) | |
2615 | { | |
2616 | lnum = le->line >> 3; | |
2617 | if (lnum >= ltable_size) | |
2618 | { | |
2619 | char *new_ltable; | |
2620 | new_ltable = (char *)realloc (ltable, ltable_size*2); | |
2621 | memset (new_ltable + ltable_size, 0, ltable_size); | |
2622 | ltable_size *= 2; | |
2623 | if (new_ltable == NULL) | |
2624 | { | |
2625 | Tcl_SetStringObj ( result_ptr->obj_ptr, "Out of memory.", -1); | |
2626 | free (ltable); | |
2627 | fclose (fp); | |
2628 | return TCL_ERROR; | |
2629 | } | |
2630 | ltable = new_ltable; | |
2631 | } | |
2632 | ltable[lnum] |= 1 << (le->line % 8); | |
2633 | } | |
2634 | } | |
2635 | ||
2636 | Tcl_DStringInit(&text_cmd_1); | |
2637 | Tcl_DStringInit(&text_cmd_2); | |
2638 | ||
2639 | ln = 1; | |
2640 | ||
2641 | widget_len = strlen (widget); | |
2642 | line[0] = '\t'; | |
2643 | ||
2644 | Tcl_DStringAppend (&text_cmd_1, widget, widget_len); | |
2645 | Tcl_DStringAppend (&text_cmd_2, widget, widget_len); | |
2646 | ||
2647 | if (linenumbers) | |
2648 | { | |
2649 | Tcl_DStringAppend (&text_cmd_1, " insert end {-\t", -1); | |
2650 | prefix_len_1 = Tcl_DStringLength(&text_cmd_1); | |
2651 | ||
2652 | Tcl_DStringAppend (&text_cmd_2, " insert end { \t", -1); | |
2653 | prefix_len_2 = Tcl_DStringLength(&text_cmd_2); | |
2654 | ||
2655 | while (fgets (line + 1, 980, fp)) | |
2656 | { | |
2657 | sprintf (line_num_buf, "%d", ln); | |
2658 | if (ltable[ln >> 3] & (1 << (ln % 8))) | |
2659 | { | |
2660 | cur_cmd = &text_cmd_1; | |
2661 | cur_prefix_len = prefix_len_1; | |
2662 | Tcl_DStringAppend (cur_cmd, line_num_buf, -1); | |
2663 | Tcl_DStringAppend (cur_cmd, "} break_tag", 11); | |
2664 | } | |
2665 | else | |
2666 | { | |
2667 | cur_cmd = &text_cmd_2; | |
2668 | cur_prefix_len = prefix_len_2; | |
2669 | Tcl_DStringAppend (cur_cmd, line_num_buf, -1); | |
2670 | Tcl_DStringAppend (cur_cmd, "} \"\"", 4); | |
2671 | } | |
2672 | ||
2673 | Tcl_DStringAppendElement (cur_cmd, line); | |
2674 | Tcl_DStringAppend (cur_cmd, " source_tag", 11); | |
2675 | ||
2676 | Tcl_Eval(interp, Tcl_DStringValue(cur_cmd)); | |
2677 | Tcl_DStringSetLength(cur_cmd, cur_prefix_len); | |
2678 | ln++; | |
2679 | } | |
2680 | } | |
2681 | else | |
2682 | { | |
2683 | Tcl_DStringAppend (&text_cmd_1, " insert end {-\t} break_tag", -1); | |
2684 | prefix_len_1 = Tcl_DStringLength(&text_cmd_1); | |
2685 | Tcl_DStringAppend (&text_cmd_2, " insert end { \t} \"\"", -1); | |
2686 | prefix_len_2 = Tcl_DStringLength(&text_cmd_2); | |
2687 | ||
2688 | ||
2689 | while (fgets (line + 1, 980, fp)) | |
2690 | { | |
2691 | if (ltable[ln >> 3] & (1 << (ln % 8))) | |
2692 | { | |
2693 | cur_cmd = &text_cmd_1; | |
2694 | cur_prefix_len = prefix_len_1; | |
2695 | } | |
2696 | else | |
2697 | { | |
2698 | cur_cmd = &text_cmd_2; | |
2699 | cur_prefix_len = prefix_len_2; | |
2700 | } | |
2701 | ||
2702 | Tcl_DStringAppendElement (cur_cmd, line); | |
2703 | Tcl_DStringAppend (cur_cmd, " source_tag", 11); | |
2704 | ||
2705 | Tcl_Eval(interp, Tcl_DStringValue(cur_cmd)); | |
2706 | Tcl_DStringSetLength(cur_cmd, cur_prefix_len); | |
2707 | ||
2708 | ln++; | |
2709 | } | |
2710 | } | |
2711 | ||
2712 | Tcl_DStringFree (&text_cmd_1); | |
2713 | Tcl_DStringFree (&text_cmd_2); | |
2714 | free (ltable); | |
2715 | fclose (fp); | |
2716 | return TCL_OK; | |
2717 | } | |
2718 | \f | |
2719 | /* | |
2720 | * This section contains commands for manipulation of breakpoints. | |
2721 | */ | |
2722 | ||
2723 | ||
2724 | /* set a breakpoint by source file and line number */ | |
2725 | /* flags are as follows: */ | |
2726 | /* least significant 2 bits are disposition, rest is */ | |
2727 | /* type (normally 0). | |
2728 | ||
2729 | enum bptype { | |
2730 | bp_breakpoint, Normal breakpoint | |
2731 | bp_hardware_breakpoint, Hardware assisted breakpoint | |
2732 | } | |
2733 | ||
2734 | Disposition of breakpoint. Ie: what to do after hitting it. | |
2735 | enum bpdisp { | |
2736 | del, Delete it | |
2737 | del_at_next_stop, Delete at next stop, whether hit or not | |
2738 | disable, Disable it | |
2739 | donttouch Leave it alone | |
2740 | }; | |
2741 | */ | |
2742 | ||
2743 | /* This implements the tcl command "gdb_set_bp" | |
2744 | * It sets breakpoints, and runs the Tcl command | |
2745 | * gdbtk_tcl_breakpoint create | |
2746 | * to register the new breakpoint with the GUI. | |
2747 | * | |
2748 | * Tcl Arguments: | |
2749 | * filename: the file in which to set the breakpoint | |
2750 | * line: the line number for the breakpoint | |
2751 | * type: the type of the breakpoint | |
2752 | * Tcl Result: | |
2753 | * The return value of the call to gdbtk_tcl_breakpoint. | |
2754 | */ | |
2755 | ||
2756 | static int | |
2757 | gdb_set_bp (clientData, interp, objc, objv) | |
2758 | ClientData clientData; | |
2759 | Tcl_Interp *interp; | |
2760 | int objc; | |
2761 | Tcl_Obj *CONST objv[]; | |
2762 | ||
2763 | { | |
2764 | struct symtab_and_line sal; | |
2765 | int line, flags, ret; | |
2766 | struct breakpoint *b; | |
2767 | char buf[64]; | |
2768 | Tcl_DString cmd; | |
2769 | ||
2770 | if (objc != 4) | |
2771 | { | |
2772 | Tcl_WrongNumArgs(interp, 1, objv, "filename line type"); | |
2773 | return TCL_ERROR; | |
2774 | } | |
2775 | ||
2776 | sal.symtab = full_lookup_symtab (Tcl_GetStringFromObj( objv[1], NULL)); | |
2777 | if (sal.symtab == NULL) | |
2778 | return TCL_ERROR; | |
2779 | ||
2780 | if (Tcl_GetIntFromObj( interp, objv[2], &line) == TCL_ERROR) | |
2781 | { | |
2782 | result_ptr->flags = GDBTK_IN_TCL_RESULT; | |
2783 | return TCL_ERROR; | |
2784 | } | |
2785 | ||
2786 | if (Tcl_GetIntFromObj( interp, objv[3], &flags) == TCL_ERROR) | |
2787 | { | |
2788 | result_ptr->flags = GDBTK_IN_TCL_RESULT; | |
2789 | return TCL_ERROR; | |
2790 | } | |
2791 | ||
2792 | sal.line = line; | |
2793 | if (!find_line_pc (sal.symtab, sal.line, &sal.pc)) | |
2794 | return TCL_ERROR; | |
2795 | ||
2796 | sal.section = find_pc_overlay (sal.pc); | |
2797 | b = set_raw_breakpoint (sal); | |
2798 | set_breakpoint_count (breakpoint_count + 1); | |
2799 | b->number = breakpoint_count; | |
2800 | b->type = flags >> 2; | |
2801 | b->disposition = flags & 3; | |
2802 | ||
2803 | /* FIXME: this won't work for duplicate basenames! */ | |
2804 | sprintf (buf, "%s:%d", basename (Tcl_GetStringFromObj ( objv[1], NULL)), line); | |
2805 | b->addr_string = strsave (buf); | |
2806 | ||
2807 | /* now send notification command back to GUI */ | |
2808 | ||
2809 | Tcl_DStringInit (&cmd); | |
2810 | ||
2811 | Tcl_DStringAppend (&cmd, "gdbtk_tcl_breakpoint create ", -1); | |
2812 | sprintf (buf, "%d", b->number); | |
2813 | Tcl_DStringAppendElement(&cmd, buf); | |
2814 | sprintf (buf, "0x%x", sal.pc); | |
2815 | Tcl_DStringAppendElement (&cmd, buf); | |
2816 | Tcl_DStringAppendElement (&cmd, Tcl_GetStringFromObj (objv[2], NULL)); | |
2817 | Tcl_DStringAppendElement (&cmd, Tcl_GetStringFromObj (objv[1], NULL)); | |
2818 | ||
2819 | ret = Tcl_Eval (interp, Tcl_DStringValue (&cmd)); | |
2820 | Tcl_DStringFree (&cmd); | |
2821 | return ret; | |
2822 | } | |
2823 | ||
2824 | /* This implements the tcl command gdb_get_breakpoint_info | |
2825 | * | |
2826 | * | |
2827 | * Tcl Arguments: | |
2828 | * breakpoint_number | |
2829 | * Tcl Result: | |
2830 | * A list with {file, function, line_number, address, type, enabled?, | |
2831 | * disposition, ignore_count, {list_of_commands}, thread, hit_count} | |
2832 | */ | |
2833 | ||
2834 | static int | |
2835 | gdb_get_breakpoint_info (clientData, interp, objc, objv) | |
2836 | ClientData clientData; | |
2837 | Tcl_Interp *interp; | |
2838 | int objc; | |
2839 | Tcl_Obj *CONST objv[]; | |
2840 | { | |
2841 | struct symtab_and_line sal; | |
2842 | static char *bptypes[] = {"breakpoint", "hardware breakpoint", "until", | |
2843 | "finish", "watchpoint", "hardware watchpoint", | |
2844 | "read watchpoint", "access watchpoint", | |
2845 | "longjmp", "longjmp resume", "step resume", | |
2846 | "through sigtramp", "watchpoint scope", | |
2847 | "call dummy" }; | |
2848 | static char *bpdisp[] = {"delete", "delstop", "disable", "donttouch"}; | |
2849 | struct command_line *cmd; | |
2850 | int bpnum; | |
2851 | struct breakpoint *b; | |
2852 | extern struct breakpoint *breakpoint_chain; | |
2853 | char *funcname, *fname, *filename; | |
2854 | Tcl_Obj *new_obj; | |
2855 | ||
2856 | if (objc != 2) | |
2857 | { | |
2858 | Tcl_SetStringObj (result_ptr->obj_ptr, "wrong number of args, should be \"breakpoint\"", -1); | |
2859 | return TCL_ERROR; | |
2860 | } | |
2861 | ||
2862 | if ( Tcl_GetIntFromObj(NULL, objv[1], &bpnum) != TCL_OK) | |
2863 | { | |
2864 | result_ptr->flags = GDBTK_IN_TCL_RESULT; | |
2865 | return TCL_ERROR; | |
2866 | } | |
2867 | ||
2868 | for (b = breakpoint_chain; b; b = b->next) | |
2869 | if (b->number == bpnum) | |
2870 | break; | |
2871 | ||
2872 | if (!b || b->type != bp_breakpoint) | |
2873 | { | |
2874 | Tcl_SetStringObj (result_ptr->obj_ptr, "Breakpoint #%d does not exist", -1); | |
2875 | return TCL_ERROR; | |
2876 | } | |
2877 | ||
2878 | sal = find_pc_line (b->address, 0); | |
2879 | ||
2880 | filename = symtab_to_filename (sal.symtab); | |
2881 | if (filename == NULL) | |
2882 | filename = ""; | |
2883 | ||
2884 | Tcl_SetListObj (result_ptr->obj_ptr ,0 ,NULL); | |
2885 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2886 | Tcl_NewStringObj (filename, -1)); | |
2887 | ||
2888 | find_pc_partial_function (b->address, &funcname, NULL, NULL); | |
2889 | fname = cplus_demangle (funcname, 0); | |
2890 | if (fname) | |
2891 | { | |
2892 | new_obj = Tcl_NewStringObj (fname, -1); | |
2893 | free (fname); | |
2894 | } | |
2895 | else | |
2896 | new_obj = Tcl_NewStringObj (funcname, -1); | |
2897 | ||
2898 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, new_obj); | |
2899 | ||
2900 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj (b->line_number)); | |
2901 | sprintf_append_element_to_obj (result_ptr->obj_ptr, "0x%lx", b->address); | |
2902 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2903 | Tcl_NewStringObj (bptypes[b->type], -1)); | |
2904 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewBooleanObj(b->enable == enabled)); | |
2905 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2906 | Tcl_NewStringObj (bpdisp[b->disposition], -1)); | |
2907 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj (b->ignore_count)); | |
2908 | ||
2909 | new_obj = Tcl_NewObj(); | |
2910 | for (cmd = b->commands; cmd; cmd = cmd->next) | |
2911 | Tcl_ListObjAppendElement (NULL, new_obj, | |
2912 | Tcl_NewStringObj (cmd->line, -1)); | |
2913 | Tcl_ListObjAppendElement(NULL, result_ptr->obj_ptr, new_obj); | |
2914 | ||
2915 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, | |
2916 | Tcl_NewStringObj (b->cond_string, -1)); | |
2917 | ||
2918 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj (b->thread)); | |
2919 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, Tcl_NewIntObj (b->hit_count)); | |
2920 | ||
2921 | return TCL_OK; | |
2922 | } | |
2923 | ||
2924 | ||
2925 | /* This implements the tcl command gdb_get_breakpoint_list | |
2926 | * It builds up a list of the current breakpoints. | |
2927 | * | |
2928 | * Tcl Arguments: | |
2929 | * None. | |
2930 | * Tcl Result: | |
2931 | * A list of breakpoint numbers. | |
2932 | */ | |
2933 | ||
2934 | static int | |
2935 | gdb_get_breakpoint_list (clientData, interp, objc, objv) | |
2936 | ClientData clientData; | |
2937 | Tcl_Interp *interp; | |
2938 | int objc; | |
2939 | Tcl_Obj *CONST objv[]; | |
2940 | { | |
2941 | struct breakpoint *b; | |
2942 | extern struct breakpoint *breakpoint_chain; | |
2943 | Tcl_Obj *new_obj; | |
2944 | ||
2945 | if (objc != 1) | |
2946 | error ("wrong number of args, none are allowed"); | |
2947 | ||
2948 | for (b = breakpoint_chain; b; b = b->next) | |
2949 | if (b->type == bp_breakpoint) | |
2950 | { | |
2951 | new_obj = Tcl_NewIntObj (b->number); | |
2952 | Tcl_ListObjAppendElement (NULL, result_ptr->obj_ptr, new_obj); | |
2953 | } | |
2954 | ||
2955 | return TCL_OK; | |
2956 | } | |
2957 | ||
2958 | \f | |
2959 | /* | |
2960 | * This section contains a bunch of miscellaneous utility commands | |
2961 | */ | |
2962 | ||
2963 | /* This implements the tcl command gdb_path_conv | |
2964 | * | |
2965 | * On Windows, it canonicalizes the pathname, | |
2966 | * On Unix, it is a no op. | |
2967 | * | |
2968 | * Arguments: | |
2969 | * path | |
2970 | * Tcl Result: | |
2971 | * The canonicalized path. | |
2972 | */ | |
2973 | ||
2974 | static int | |
2975 | gdb_path_conv (clientData, interp, objc, objv) | |
2976 | ClientData clientData; | |
2977 | Tcl_Interp *interp; | |
2978 | int objc; | |
2979 | Tcl_Obj *CONST objv[]; | |
2980 | { | |
2981 | if (objc != 2) | |
2982 | error ("wrong # args"); | |
2983 | ||
2984 | #ifdef WINNT | |
2985 | { | |
2986 | char pathname[256], *ptr; | |
2987 | ||
2988 | cygwin32_conv_to_full_win32_path (Tcl_GetStringFromObj(objv[1], NULL), pathname); | |
2989 | for (ptr = pathname; *ptr; ptr++) | |
2990 | { | |
2991 | if (*ptr == '\\') | |
2992 | *ptr = '/'; | |
2993 | } | |
2994 | Tcl_SetStringObj (result_ptr->obj_ptr, pathname, -1); | |
2995 | } | |
2996 | #else | |
2997 | Tcl_SetStringObj (result_ptr->obj_ptr, Tcl_GetStringFromObj (objv[1], NULL), -1); | |
2998 | #endif | |
2999 | ||
3000 | return TCL_OK; | |
3001 | } | |
3002 | \f | |
3003 | /* | |
3004 | * This section has utility routines that are not Tcl commands. | |
3005 | */ | |
3006 | ||
3007 | static int | |
3008 | perror_with_name_wrapper (args) | |
3009 | char * args; | |
3010 | { | |
3011 | perror_with_name (args); | |
3012 | return 1; | |
3013 | } | |
3014 | ||
3015 | /* The lookup_symtab() in symtab.c doesn't work correctly */ | |
3016 | /* It will not work will full pathnames and if multiple */ | |
3017 | /* source files have the same basename, it will return */ | |
3018 | /* the first one instead of the correct one. This version */ | |
3019 | /* also always makes sure symtab->fullname is set. */ | |
3020 | ||
3021 | static struct symtab * | |
3022 | full_lookup_symtab(file) | |
3023 | char *file; | |
3024 | { | |
3025 | struct symtab *st; | |
3026 | struct objfile *objfile; | |
3027 | char *bfile, *fullname; | |
3028 | struct partial_symtab *pt; | |
3029 | ||
3030 | if (!file) | |
3031 | return NULL; | |
3032 | ||
3033 | /* first try a direct lookup */ | |
3034 | st = lookup_symtab (file); | |
3035 | if (st) | |
3036 | { | |
3037 | if (!st->fullname) | |
3038 | symtab_to_filename(st); | |
3039 | return st; | |
3040 | } | |
3041 | ||
3042 | /* if the direct approach failed, try */ | |
3043 | /* looking up the basename and checking */ | |
3044 | /* all matches with the fullname */ | |
3045 | bfile = basename (file); | |
3046 | ALL_SYMTABS (objfile, st) | |
3047 | { | |
3048 | if (!strcmp (bfile, basename(st->filename))) | |
3049 | { | |
3050 | if (!st->fullname) | |
3051 | fullname = symtab_to_filename (st); | |
3052 | else | |
3053 | fullname = st->fullname; | |
3054 | ||
3055 | if (!strcmp (file, fullname)) | |
3056 | return st; | |
3057 | } | |
3058 | } | |
3059 | ||
3060 | /* still no luck? look at psymtabs */ | |
3061 | ALL_PSYMTABS (objfile, pt) | |
3062 | { | |
3063 | if (!strcmp (bfile, basename(pt->filename))) | |
3064 | { | |
3065 | st = PSYMTAB_TO_SYMTAB (pt); | |
3066 | if (st) | |
3067 | { | |
3068 | fullname = symtab_to_filename (st); | |
3069 | if (!strcmp (file, fullname)) | |
3070 | return st; | |
3071 | } | |
3072 | } | |
3073 | } | |
3074 | return NULL; | |
3075 | } |