Commit | Line | Data |
---|---|---|
ca4e7e14 JI |
1 | /* Startup code 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 | int in_fputs = 0; | |
75 | ||
3d64f1e0 KS |
76 | extern int (*ui_load_progress_hook) PARAMS ((char *, unsigned long)); |
77 | extern void (*pre_add_symbol_hook) PARAMS ((char *)); | |
78 | extern void (*post_add_symbol_hook) PARAMS ((void)); | |
79 | extern void (*selected_frame_level_changed_hook) PARAMS ((int)); | |
ca4e7e14 JI |
80 | #ifdef __CYGWIN32__ |
81 | extern void (*ui_loop_hook) PARAMS ((int)); | |
82 | #endif | |
3d64f1e0 | 83 | |
ca4e7e14 JI |
84 | static void gdbtk_create_tracepoint PARAMS ((struct tracepoint *)); |
85 | static void gdbtk_delete_tracepoint PARAMS ((struct tracepoint *)); | |
86 | static void gdbtk_modify_tracepoint PARAMS ((struct tracepoint *)); | |
63d138d9 | 87 | static void gdbtk_trace_find PARAMS ((char *arg, int from_tty)); |
ca4e7e14 JI |
88 | static void gdbtk_create_breakpoint PARAMS ((struct breakpoint *)); |
89 | static void gdbtk_delete_breakpoint PARAMS ((struct breakpoint *)); | |
90 | static void gdbtk_modify_breakpoint PARAMS ((struct breakpoint *)); | |
4fb67eb5 KS |
91 | static void gdbtk_file_changed PARAMS ((char *)); |
92 | static void gdbtk_exec_file_display PARAMS ((char *)); | |
ca4e7e14 JI |
93 | static void tk_command_loop PARAMS ((void)); |
94 | static void gdbtk_call_command PARAMS ((struct cmd_list_element *, char *, int)); | |
95 | static int gdbtk_wait PARAMS ((int, struct target_waitstatus *)); | |
96 | void x_event PARAMS ((int)); | |
97 | static int gdbtk_query PARAMS ((const char *, va_list)); | |
98 | static void gdbtk_warning PARAMS ((const char *, va_list)); | |
99 | void gdbtk_ignorable_warning PARAMS ((const char *)); | |
100 | static char* gdbtk_readline PARAMS ((char *)); | |
101 | static void | |
102 | #ifdef ANSI_PROTOTYPES | |
103 | gdbtk_readline_begin (char *format, ...); | |
104 | #else | |
105 | gdbtk_readline_begin (); | |
106 | #endif | |
107 | static void gdbtk_readline_end PARAMS ((void)); | |
108 | static void gdbtk_flush PARAMS ((FILE *)); | |
109 | static void gdbtk_pre_add_symbol PARAMS ((char *)); | |
110 | static void gdbtk_print_frame_info PARAMS ((struct symtab *, int, int, int)); | |
111 | static void gdbtk_post_add_symbol PARAMS ((void)); | |
112 | static void pc_changed PARAMS ((void)); | |
113 | static void tracepoint_notify PARAMS ((struct tracepoint *, const char *)); | |
3d64f1e0 | 114 | static void gdbtk_selected_frame_changed PARAMS ((int)); |
4ff5d55a | 115 | static void gdbtk_context_change PARAMS ((int)); |
ca4e7e14 JI |
116 | |
117 | /* | |
118 | * gdbtk_fputs can't be static, because we need to call it in gdbtk.c. | |
119 | * See note there for details. | |
120 | */ | |
121 | ||
122 | void gdbtk_fputs PARAMS ((const char *, FILE *)); | |
123 | int gdbtk_load_hash PARAMS ((char *, unsigned long)); | |
124 | static void breakpoint_notify PARAMS ((struct breakpoint *, const char *)); | |
125 | ||
126 | /* | |
127 | * gdbtk_add_hooks - add all the hooks to gdb. This will get called by the | |
128 | * startup code to fill in the hooks needed by core gdb. | |
129 | */ | |
130 | ||
131 | void | |
132 | gdbtk_add_hooks(void) | |
133 | { | |
134 | command_loop_hook = tk_command_loop; | |
135 | call_command_hook = gdbtk_call_command; | |
136 | readline_begin_hook = gdbtk_readline_begin; | |
137 | readline_hook = gdbtk_readline; | |
138 | readline_end_hook = gdbtk_readline_end; | |
139 | ||
140 | print_frame_info_listing_hook = gdbtk_print_frame_info; | |
141 | query_hook = gdbtk_query; | |
142 | warning_hook = gdbtk_warning; | |
143 | flush_hook = gdbtk_flush; | |
144 | ||
145 | create_breakpoint_hook = gdbtk_create_breakpoint; | |
146 | delete_breakpoint_hook = gdbtk_delete_breakpoint; | |
147 | modify_breakpoint_hook = gdbtk_modify_breakpoint; | |
148 | ||
2c04e0d9 KS |
149 | interactive_hook = gdbtk_interactive; |
150 | target_wait_hook = gdbtk_wait; | |
151 | ui_load_progress_hook = gdbtk_load_hash; | |
152 | ||
ca4e7e14 JI |
153 | #ifdef __CYGWIN32__ |
154 | ui_loop_hook = x_event; | |
155 | #endif | |
2c04e0d9 KS |
156 | pre_add_symbol_hook = gdbtk_pre_add_symbol; |
157 | post_add_symbol_hook = gdbtk_post_add_symbol; | |
4fb67eb5 KS |
158 | file_changed_hook = gdbtk_file_changed; |
159 | exec_file_display_hook = gdbtk_exec_file_display; | |
ca4e7e14 JI |
160 | |
161 | create_tracepoint_hook = gdbtk_create_tracepoint; | |
162 | delete_tracepoint_hook = gdbtk_delete_tracepoint; | |
163 | modify_tracepoint_hook = gdbtk_modify_tracepoint; | |
63d138d9 | 164 | trace_find_hook = gdbtk_trace_find; |
2c04e0d9 | 165 | |
ca4e7e14 | 166 | pc_changed_hook = pc_changed; |
3d64f1e0 | 167 | selected_frame_level_changed_hook = gdbtk_selected_frame_changed; |
4ff5d55a | 168 | context_hook = gdbtk_context_change; |
ca4e7e14 JI |
169 | } |
170 | ||
171 | /* These control where to put the gdb output which is created by | |
172 | {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the | |
173 | lowest level of these routines and capture all output from the rest of GDB. | |
174 | ||
175 | The reason to use the result_ptr rather than the gdbtk_interp's result | |
176 | directly is so that a call_wrapper invoked function can preserve its result | |
177 | across calls into Tcl which might be made in the course of the function's | |
178 | execution. | |
179 | ||
180 | * result_ptr->obj_ptr is where to accumulate the result. | |
181 | * GDBTK_TO_RESULT flag means the output goes to the gdbtk_tcl_fputs proc | |
182 | instead of to the result_ptr. | |
183 | * GDBTK_MAKES_LIST flag means add to the result as a list element. | |
184 | ||
185 | */ | |
186 | ||
187 | gdbtk_result *result_ptr = NULL; | |
188 | \f | |
189 | ||
190 | /* This allows you to Tcl_Eval a tcl command which takes | |
191 | a command word, and then a single argument. */ | |
192 | ||
193 | int gdbtk_two_elem_cmd (cmd_name, argv1) | |
194 | char *cmd_name; | |
195 | char * argv1; | |
196 | { | |
197 | char *command; | |
198 | int result, flags_ptr, arg_len, cmd_len; | |
199 | ||
200 | arg_len = Tcl_ScanElement (argv1, &flags_ptr); | |
201 | cmd_len = strlen (cmd_name); | |
202 | command = malloc(arg_len + cmd_len + 2); | |
203 | strcpy (command, cmd_name); | |
204 | strcat (command, " "); | |
205 | ||
206 | Tcl_ConvertElement (argv1, command + cmd_len + 1, flags_ptr); | |
207 | ||
208 | result = Tcl_Eval (gdbtk_interp, command); | |
209 | free (command); | |
210 | return result; | |
211 | ||
212 | } | |
213 | ||
214 | static void | |
215 | gdbtk_flush (stream) | |
216 | FILE *stream; | |
217 | { | |
218 | #if 0 | |
219 | /* Force immediate screen update */ | |
220 | ||
221 | Tcl_VarEval (gdbtk_interp, "gdbtk_tcl_flush", NULL); | |
222 | #endif | |
223 | } | |
224 | ||
225 | /* This handles all the output from gdb. All the gdb printf_xxx functions | |
226 | * eventually end up here. The output is either passed to the result_ptr | |
227 | * where it will go to the result of some gdbtk command, or passed to the | |
228 | * Tcl proc gdbtk_tcl_fputs (where it is usually just dumped to the console | |
229 | * window. | |
230 | * | |
231 | * The cases are: | |
232 | * | |
233 | * 1) result_ptr == NULL - This happens when some output comes from gdb which | |
f3b86a30 | 234 | * is not generated by a command in gdbtk-cmds, usually startup stuff. |
ca4e7e14 JI |
235 | * In this case we just route the data to gdbtk_tcl_fputs. |
236 | * 2) The GDBTK_TO_RESULT flag is set - The result is supposed to go to Tcl. | |
237 | * We place the data into the result_ptr, either as a string, | |
238 | * or a list, depending whether the GDBTK_MAKES_LIST bit is set. | |
239 | * 3) The GDBTK_TO_RESULT flag is unset - We route the data to gdbtk_tcl_fputs | |
240 | * UNLESS it was coming to stderr. Then we place it in the result_ptr | |
241 | * anyway, so it can be dealt with. | |
242 | * | |
243 | */ | |
244 | ||
245 | void | |
246 | gdbtk_fputs (ptr, stream) | |
247 | const char *ptr; | |
248 | FILE *stream; | |
249 | { | |
250 | in_fputs = 1; | |
251 | ||
252 | if (result_ptr != NULL) | |
253 | { | |
254 | if (result_ptr->flags & GDBTK_TO_RESULT) | |
255 | { | |
256 | if (result_ptr->flags & GDBTK_MAKES_LIST) | |
257 | Tcl_ListObjAppendElement(NULL, result_ptr->obj_ptr, | |
258 | Tcl_NewStringObj((char *) ptr, -1)); | |
259 | else | |
260 | Tcl_AppendToObj (result_ptr->obj_ptr, (char *) ptr, -1); | |
261 | } | |
262 | else if (stream == gdb_stderr) | |
263 | { | |
264 | if (result_ptr->flags & GDBTK_ERROR_STARTED) | |
265 | Tcl_AppendToObj (result_ptr->obj_ptr, (char *) ptr, -1); | |
266 | else | |
267 | { | |
268 | Tcl_SetStringObj (result_ptr->obj_ptr, (char *) ptr, -1); | |
269 | result_ptr->flags |= GDBTK_ERROR_STARTED; | |
270 | } | |
271 | } | |
272 | else | |
273 | { | |
274 | gdbtk_two_elem_cmd ("gdbtk_tcl_fputs", (char *) ptr); | |
275 | if (result_ptr->flags & GDBTK_MAKES_LIST) | |
276 | gdbtk_two_elem_cmd ("gdbtk_tcl_fputs", " "); | |
277 | } | |
278 | } | |
279 | else | |
280 | { | |
281 | gdbtk_two_elem_cmd ("gdbtk_tcl_fputs", (char *) ptr); | |
282 | } | |
283 | ||
284 | in_fputs = 0; | |
285 | } | |
286 | ||
287 | /* | |
288 | * This routes all warnings to the Tcl function "gdbtk_tcl_warning". | |
289 | */ | |
290 | ||
291 | static void | |
292 | gdbtk_warning (warning, args) | |
293 | const char *warning; | |
294 | va_list args; | |
295 | { | |
296 | char buf[200]; | |
297 | ||
298 | vsprintf (buf, warning, args); | |
299 | gdbtk_two_elem_cmd ("gdbtk_tcl_warning", buf); | |
300 | ||
301 | } | |
302 | ||
303 | /* | |
304 | * This routes all ignorable warnings to the Tcl function | |
305 | * "gdbtk_tcl_ignorable_warning". | |
306 | */ | |
307 | ||
308 | void | |
309 | gdbtk_ignorable_warning (warning) | |
310 | const char *warning; | |
311 | { | |
6f5af15b | 312 | char buf[512]; |
ca4e7e14 JI |
313 | sprintf (buf, warning); |
314 | gdbtk_two_elem_cmd ("gdbtk_tcl_ignorable_warning", buf); | |
ca4e7e14 JI |
315 | } |
316 | ||
ca4e7e14 JI |
317 | static void |
318 | pc_changed() | |
319 | { | |
320 | Tcl_Eval (gdbtk_interp, "gdbtk_pc_changed"); | |
321 | } | |
322 | ||
323 | \f | |
324 | /* This function is called instead of gdb's internal command loop. This is the | |
325 | last chance to do anything before entering the main Tk event loop. | |
326 | At the end of the command, we enter the main loop. */ | |
327 | ||
328 | static void | |
329 | tk_command_loop () | |
330 | { | |
331 | extern GDB_FILE *instream; | |
332 | ||
333 | /* We no longer want to use stdin as the command input stream */ | |
334 | instream = NULL; | |
335 | ||
336 | if (Tcl_Eval (gdbtk_interp, "gdbtk_tcl_preloop") != TCL_OK) | |
337 | { | |
338 | char *msg; | |
339 | ||
340 | /* Force errorInfo to be set up propertly. */ | |
341 | Tcl_AddErrorInfo (gdbtk_interp, ""); | |
342 | ||
343 | msg = Tcl_GetVar (gdbtk_interp, "errorInfo", TCL_GLOBAL_ONLY); | |
344 | #ifdef _WIN32 | |
345 | MessageBox (NULL, msg, NULL, MB_OK | MB_ICONERROR | MB_TASKMODAL); | |
346 | #else | |
347 | fputs_unfiltered (msg, gdb_stderr); | |
348 | #endif | |
349 | } | |
350 | ||
351 | #ifdef _WIN32 | |
352 | close_bfds (); | |
353 | #endif | |
354 | ||
355 | Tk_MainLoop (); | |
356 | } | |
357 | ||
358 | /* Come here when there is activity on the X file descriptor. */ | |
359 | ||
360 | void | |
361 | x_event (signo) | |
362 | int signo; | |
363 | { | |
364 | static int in_x_event = 0; | |
365 | static Tcl_Obj *varname = NULL; | |
366 | if (in_x_event || in_fputs) | |
367 | return; | |
368 | ||
369 | in_x_event = 1; | |
370 | ||
371 | #ifdef __CYGWIN32__ | |
372 | if (signo == -2) | |
373 | gdbtk_stop_timer (); | |
374 | #endif | |
375 | ||
376 | /* Process pending events */ | |
377 | while (Tcl_DoOneEvent (TCL_DONT_WAIT|TCL_ALL_EVENTS) != 0) | |
378 | ; | |
379 | ||
380 | if (load_in_progress) | |
381 | { | |
382 | int val; | |
383 | if (varname == NULL) | |
384 | { | |
385 | Tcl_Obj *varnamestrobj = Tcl_NewStringObj("download_cancel_ok",-1); | |
386 | varname = Tcl_ObjGetVar2(gdbtk_interp,varnamestrobj,NULL,TCL_GLOBAL_ONLY); | |
387 | } | |
388 | if ((Tcl_GetIntFromObj(gdbtk_interp,varname,&val) == TCL_OK) && val) | |
389 | { | |
390 | quit_flag = 1; | |
391 | #ifdef REQUEST_QUIT | |
392 | REQUEST_QUIT; | |
393 | #else | |
394 | if (immediate_quit) | |
395 | quit (); | |
396 | #endif | |
397 | } | |
398 | } | |
399 | in_x_event = 0; | |
400 | } | |
401 | ||
402 | /* VARARGS */ | |
403 | static void | |
404 | #ifdef ANSI_PROTOTYPES | |
405 | gdbtk_readline_begin (char *format, ...) | |
406 | #else | |
407 | gdbtk_readline_begin (va_alist) | |
408 | va_dcl | |
409 | #endif | |
410 | { | |
411 | va_list args; | |
6f5af15b | 412 | char buf[200]; |
ca4e7e14 JI |
413 | |
414 | #ifdef ANSI_PROTOTYPES | |
415 | va_start (args, format); | |
416 | #else | |
417 | char *format; | |
418 | va_start (args); | |
419 | format = va_arg (args, char *); | |
420 | #endif | |
421 | ||
422 | vsprintf (buf, format, args); | |
423 | gdbtk_two_elem_cmd ("gdbtk_tcl_readline_begin", buf); | |
424 | ||
425 | } | |
426 | ||
427 | static char * | |
428 | gdbtk_readline (prompt) | |
429 | char *prompt; | |
430 | { | |
431 | int result; | |
432 | ||
433 | #ifdef _WIN32 | |
434 | close_bfds (); | |
435 | #endif | |
436 | ||
437 | result = gdbtk_two_elem_cmd ("gdbtk_tcl_readline", prompt); | |
438 | ||
439 | if (result == TCL_OK) | |
440 | { | |
441 | return (strdup (gdbtk_interp -> result)); | |
442 | } | |
443 | else | |
444 | { | |
445 | gdbtk_fputs (gdbtk_interp -> result, gdb_stdout); | |
446 | gdbtk_fputs ("\n", gdb_stdout); | |
447 | return (NULL); | |
448 | } | |
449 | } | |
450 | ||
451 | static void | |
452 | gdbtk_readline_end () | |
453 | { | |
454 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_readline_end"); | |
455 | } | |
456 | ||
457 | static void | |
458 | gdbtk_call_command (cmdblk, arg, from_tty) | |
459 | struct cmd_list_element *cmdblk; | |
460 | char *arg; | |
461 | int from_tty; | |
462 | { | |
463 | running_now = 0; | |
464 | if (cmdblk->class == class_run || cmdblk->class == class_trace) | |
465 | { | |
466 | ||
3d64f1e0 KS |
467 | /* HACK! HACK! This is to get the gui to update the tstart/tstop |
468 | button only incase of tstart/tstop commands issued from the console | |
469 | We don't want to update the src window, so we need to have specific | |
470 | procedures to do tstart and tstop | |
471 | Unfortunately this will not display errors from tstart or tstop in the | |
472 | console window itself, but as dialogs.*/ | |
ca4e7e14 JI |
473 | |
474 | if (!strcmp(cmdblk->name, "tstart") && !No_Update) | |
475 | { | |
3d64f1e0 KS |
476 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_tstart"); |
477 | (*cmdblk->function.cfunc)(arg, from_tty); | |
ca4e7e14 JI |
478 | } |
479 | else if (!strcmp(cmdblk->name, "tstop") && !No_Update) | |
3d64f1e0 KS |
480 | { |
481 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_tstop"); | |
482 | (*cmdblk->function.cfunc)(arg, from_tty); | |
483 | } | |
484 | /* end of hack */ | |
485 | else | |
486 | { | |
487 | running_now = 1; | |
488 | if (!No_Update) | |
489 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_busy"); | |
490 | (*cmdblk->function.cfunc)(arg, from_tty); | |
491 | running_now = 0; | |
492 | if (!No_Update) | |
493 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_idle"); | |
494 | } | |
ca4e7e14 JI |
495 | } |
496 | else | |
497 | (*cmdblk->function.cfunc)(arg, from_tty); | |
498 | } | |
499 | ||
500 | /* The next three functions use breakpoint_notify to allow the GUI | |
501 | * to handle creating, deleting and modifying breakpoints. These three | |
502 | * functions are put into the appropriate gdb hooks in gdbtk_init. | |
503 | */ | |
504 | ||
505 | static void | |
506 | gdbtk_create_breakpoint(b) | |
507 | struct breakpoint *b; | |
508 | { | |
509 | breakpoint_notify (b, "create"); | |
510 | } | |
511 | ||
512 | static void | |
513 | gdbtk_delete_breakpoint(b) | |
514 | struct breakpoint *b; | |
515 | { | |
516 | breakpoint_notify (b, "delete"); | |
517 | } | |
518 | ||
519 | static void | |
520 | gdbtk_modify_breakpoint(b) | |
521 | struct breakpoint *b; | |
522 | { | |
523 | breakpoint_notify (b, "modify"); | |
524 | } | |
525 | ||
526 | /* This is the generic function for handling changes in | |
527 | * a breakpoint. It routes the information to the Tcl | |
528 | * command "gdbtk_tcl_breakpoint" in the form: | |
529 | * gdbtk_tcl_breakpoint action b_number b_address b_line b_file | |
530 | * On error, the error string is written to gdb_stdout. | |
531 | */ | |
532 | ||
533 | static void | |
534 | breakpoint_notify(b, action) | |
535 | struct breakpoint *b; | |
536 | const char *action; | |
537 | { | |
538 | char buf[256]; | |
539 | int v; | |
540 | struct symtab_and_line sal; | |
541 | char *filename; | |
542 | ||
543 | if (b->type != bp_breakpoint) | |
544 | return; | |
545 | ||
546 | /* We ensure that ACTION contains no special Tcl characters, so we | |
547 | can do this. */ | |
548 | sal = find_pc_line (b->address, 0); | |
549 | filename = symtab_to_filename (sal.symtab); | |
550 | if (filename == NULL) | |
551 | filename = ""; | |
552 | ||
63d138d9 JI |
553 | sprintf (buf, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s} {%s} %d %d", |
554 | action, b->number, (long)b->address, b->line_number, filename, | |
555 | bpdisp[b->disposition], b->enable, b->thread); | |
ca4e7e14 JI |
556 | |
557 | v = Tcl_Eval (gdbtk_interp, buf); | |
558 | ||
559 | if (v != TCL_OK) | |
560 | { | |
561 | gdbtk_fputs (Tcl_GetStringResult (gdbtk_interp), gdb_stdout); | |
562 | gdbtk_fputs ("\n", gdb_stdout); | |
563 | } | |
564 | } | |
565 | ||
566 | int | |
567 | gdbtk_load_hash (section, num) | |
568 | char *section; | |
569 | unsigned long num; | |
570 | { | |
571 | char buf[128]; | |
572 | sprintf (buf, "download_hash %s %ld", section, num); | |
573 | Tcl_Eval (gdbtk_interp, buf); | |
574 | return atoi (gdbtk_interp->result); | |
575 | } | |
576 | ||
577 | ||
578 | /* This hook is called whenever we are ready to load a symbol file so that | |
579 | the UI can notify the user... */ | |
580 | static void | |
581 | gdbtk_pre_add_symbol (name) | |
582 | char *name; | |
583 | { | |
584 | ||
585 | gdbtk_two_elem_cmd("gdbtk_tcl_pre_add_symbol", name); | |
586 | ||
587 | } | |
588 | ||
589 | /* This hook is called whenever we finish loading a symbol file. */ | |
590 | static void | |
591 | gdbtk_post_add_symbol () | |
592 | { | |
593 | Tcl_Eval (gdbtk_interp, "gdbtk_tcl_post_add_symbol"); | |
594 | } | |
595 | ||
596 | /* This hook function is called whenever we want to wait for the | |
597 | target. */ | |
598 | ||
599 | static int | |
600 | gdbtk_wait (pid, ourstatus) | |
601 | int pid; | |
602 | struct target_waitstatus *ourstatus; | |
603 | { | |
4ce8d0e9 KS |
604 | /* Don't run the timer on various targets... */ |
605 | if (!STREQ (target_shortname, "ice")) | |
606 | gdbtk_start_timer (); | |
ca4e7e14 JI |
607 | pid = target_wait (pid, ourstatus); |
608 | gdbtk_stop_timer (); | |
609 | return pid; | |
610 | } | |
611 | ||
612 | /* | |
613 | * This handles all queries from gdb. | |
614 | * The first argument is a printf style format statement, the rest are its | |
615 | * arguments. The resultant formatted string is passed to the Tcl function | |
616 | * "gdbtk_tcl_query". | |
617 | * It returns the users response to the query, as well as putting the value | |
618 | * in the result field of the Tcl interpreter. | |
619 | */ | |
620 | ||
621 | static int | |
622 | gdbtk_query (query, args) | |
623 | const char *query; | |
624 | va_list args; | |
625 | { | |
626 | char buf[200]; | |
627 | long val; | |
628 | ||
629 | vsprintf (buf, query, args); | |
630 | gdbtk_two_elem_cmd ("gdbtk_tcl_query", buf); | |
631 | ||
632 | val = atol (gdbtk_interp->result); | |
633 | return val; | |
634 | } | |
635 | ||
636 | ||
637 | static void | |
638 | gdbtk_print_frame_info (s, line, stopline, noerror) | |
639 | struct symtab *s; | |
640 | int line; | |
641 | int stopline; | |
642 | int noerror; | |
643 | { | |
644 | current_source_symtab = s; | |
645 | current_source_line = line; | |
646 | } | |
647 | ||
648 | static void | |
649 | gdbtk_create_tracepoint (tp) | |
650 | struct tracepoint *tp; | |
651 | { | |
652 | tracepoint_notify (tp, "create"); | |
653 | } | |
654 | ||
655 | static void | |
656 | gdbtk_delete_tracepoint (tp) | |
657 | struct tracepoint *tp; | |
658 | { | |
659 | tracepoint_notify (tp, "delete"); | |
660 | } | |
661 | ||
662 | static void | |
663 | gdbtk_modify_tracepoint (tp) | |
664 | struct tracepoint *tp; | |
665 | { | |
666 | tracepoint_notify (tp, "modify"); | |
667 | } | |
668 | ||
669 | static void | |
670 | tracepoint_notify(tp, action) | |
671 | struct tracepoint *tp; | |
672 | const char *action; | |
673 | { | |
674 | char buf[256]; | |
675 | int v; | |
676 | struct symtab_and_line sal; | |
677 | char *filename; | |
678 | ||
679 | /* We ensure that ACTION contains no special Tcl characters, so we | |
680 | can do this. */ | |
681 | sal = find_pc_line (tp->address, 0); | |
682 | ||
683 | filename = symtab_to_filename (sal.symtab); | |
684 | if (filename == NULL) | |
685 | filename = "N/A"; | |
6f5af15b | 686 | sprintf (buf, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s} %d", action, tp->number, |
ca4e7e14 JI |
687 | (long)tp->address, sal.line, filename, tp->pass_count); |
688 | ||
689 | v = Tcl_Eval (gdbtk_interp, buf); | |
690 | ||
691 | if (v != TCL_OK) | |
692 | { | |
693 | gdbtk_fputs (gdbtk_interp->result, gdb_stdout); | |
694 | gdbtk_fputs ("\n", gdb_stdout); | |
695 | } | |
696 | } | |
697 | ||
63d138d9 JI |
698 | /* |
699 | * gdbtk_trace_find | |
700 | * | |
701 | * This is run by the trace_find_command. arg is the argument that was passed | |
702 | * to that command, from_tty is 1 if the command was run from a tty, 0 if it | |
703 | * was run from a script. It runs gdbtk_tcl_tfind_hook passing on these two | |
704 | * arguments. | |
705 | * | |
706 | */ | |
707 | ||
708 | static void | |
709 | gdbtk_trace_find (arg, from_tty) | |
710 | char *arg; | |
711 | int from_tty; | |
712 | { | |
713 | Tcl_Obj *cmdObj; | |
714 | ||
715 | Tcl_GlobalEval (gdbtk_interp, "debug {***In gdbtk_trace_find...}"); | |
716 | cmdObj = Tcl_NewListObj (0, NULL); | |
717 | Tcl_ListObjAppendElement (gdbtk_interp, cmdObj, | |
718 | Tcl_NewStringObj ("gdbtk_tcl_trace_find_hook", -1)); | |
719 | Tcl_ListObjAppendElement (gdbtk_interp, cmdObj, Tcl_NewStringObj (arg, -1)); | |
720 | Tcl_ListObjAppendElement (gdbtk_interp, cmdObj, Tcl_NewIntObj(from_tty)); | |
721 | Tcl_GlobalEvalObj (gdbtk_interp, cmdObj); | |
722 | ||
723 | } | |
724 | ||
3d64f1e0 KS |
725 | static void |
726 | gdbtk_selected_frame_changed (level) | |
727 | int level; | |
728 | { | |
729 | Tcl_UpdateLinkedVar (gdbtk_interp, "gdb_selected_frame_level"); | |
730 | } | |
4ff5d55a MH |
731 | |
732 | /* Called when the current thread changes. */ | |
733 | /* gdb_context is linked to the tcl variable "gdb_context_id" */ | |
734 | static void | |
735 | gdbtk_context_change (num) | |
736 | int num; | |
737 | { | |
738 | gdb_context = num; | |
739 | } | |
2c04e0d9 | 740 | |
4fb67eb5 KS |
741 | /* Called from file_command */ |
742 | static void | |
743 | gdbtk_file_changed (filename) | |
744 | char *filename; | |
745 | { | |
746 | gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", filename); | |
747 | } | |
748 | ||
2c04e0d9 KS |
749 | /* Called from exec_file_command */ |
750 | static void | |
4fb67eb5 | 751 | gdbtk_exec_file_display (filename) |
2c04e0d9 KS |
752 | char *filename; |
753 | { | |
4fb67eb5 | 754 | gdbtk_two_elem_cmd ("gdbtk_tcl_exec_file_display", filename); |
2c04e0d9 | 755 | } |