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