1 /* Tcl/Tk interface routines.
2 Copyright 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 Written by Stu Grossman <grossman@cygnus.com> of Cygnus Support.
6 This file is part of GDB.
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.
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.
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. */
31 #include "tracepoint.h"
45 /* start-sanitize-ide */
49 /* end-sanitize-ide */
52 #ifdef ANSI_PROTOTYPES
62 #include <sys/ioctl.h>
63 #include "gdb_string.h"
70 #include <sys/stropts.h>
80 #define GDBTK_PATH_SEP ";"
82 #define GDBTK_PATH_SEP ":"
85 /* Some versions (1.3.79, 1.3.81) of Linux don't support SIOCSPGRP the way
86 gdbtk wants to use it... */
91 static int No_Update
= 0;
92 static int load_in_progress
= 0;
93 static int in_fputs
= 0;
95 int gdbtk_load_hash
PARAMS ((char *, unsigned long));
96 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
97 void (*pre_add_symbol_hook
) PARAMS ((char *));
98 void (*post_add_symbol_hook
) PARAMS ((void));
100 /* This is a disgusting hack. Unfortunately, the UI will lock up if we
101 are doing something like blocking in a system call, waiting for serial I/O,
104 This hook should be used whenever we might block. This means adding appropriate
105 timeouts to code and what not to allow this hook to be called. */
106 void (*ui_loop_hook
) PARAMS ((int));
108 char * get_prompt
PARAMS ((void));
110 static void null_routine
PARAMS ((int));
111 static void gdbtk_flush
PARAMS ((FILE *));
112 static void gdbtk_fputs
PARAMS ((const char *, FILE *));
113 static int gdbtk_query
PARAMS ((const char *, va_list));
114 static char *gdbtk_readline
PARAMS ((char *));
115 static void gdbtk_init
PARAMS ((char *));
116 static void tk_command_loop
PARAMS ((void));
117 static void gdbtk_call_command
PARAMS ((struct cmd_list_element
*, char *, int));
118 static int gdbtk_wait
PARAMS ((int, struct target_waitstatus
*));
119 static void x_event
PARAMS ((int));
120 static void gdbtk_interactive
PARAMS ((void));
121 static void cleanup_init
PARAMS ((int));
122 static void tk_command
PARAMS ((char *, int));
123 static int gdb_disassemble
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
124 static int compare_lines
PARAMS ((const PTR
, const PTR
));
125 static int gdbtk_dis_asm_read_memory
PARAMS ((bfd_vma
, bfd_byte
*, int, disassemble_info
*));
126 static int gdb_path_conv
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
127 static int gdb_stop
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
128 static int gdb_confirm_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
129 static int gdb_force_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
130 static int gdb_listfiles
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
131 static int gdb_listfuncs
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
132 static int call_wrapper
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
133 static int gdb_cmd
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
134 static int gdb_immediate_command
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
135 static int gdb_fetch_registers
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
136 static void gdbtk_readline_end
PARAMS ((void));
137 static void pc_changed
PARAMS ((void));
138 static int gdb_changed_register_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
139 static void register_changed_p
PARAMS ((int, void *));
140 static int gdb_get_breakpoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
141 static int gdb_get_breakpoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
142 static void breakpoint_notify
PARAMS ((struct breakpoint
*, const char *));
143 static void gdbtk_create_breakpoint
PARAMS ((struct breakpoint
*));
144 static void gdbtk_delete_breakpoint
PARAMS ((struct breakpoint
*));
145 static void gdbtk_modify_breakpoint
PARAMS ((struct breakpoint
*));
146 static int gdb_loc
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
147 static int gdb_eval
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
148 static int map_arg_registers
PARAMS ((int, char *[], void (*) (int, void *), void *));
149 static void get_register_name
PARAMS ((int, void *));
150 static int gdb_regnames
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
151 static void get_register
PARAMS ((int, void *));
152 static int gdb_trace_status
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
153 static int gdb_target_has_execution_command
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
154 static int gdb_load_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
155 void TclDebug
PARAMS ((const char *fmt
, ...));
156 static int gdb_get_vars_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
157 static int gdb_get_function_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
158 static int gdb_get_line_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
159 static int gdb_get_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
160 static int gdb_tracepoint_exists_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
161 static int gdb_get_tracepoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
162 static int gdb_actions_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
163 static int gdb_prompt_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
164 static int gdb_find_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
165 static int gdb_get_tracepoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
166 static void gdbtk_create_tracepoint
PARAMS ((struct tracepoint
*));
167 static void gdbtk_delete_tracepoint
PARAMS ((struct tracepoint
*));
168 static void gdbtk_modify_tracepoint
PARAMS ((struct tracepoint
*));
169 static void tracepoint_notify
PARAMS ((struct tracepoint
*, const char *));
170 static void gdbtk_print_frame_info
PARAMS ((struct symtab
*, int, int, int));
171 void gdbtk_pre_add_symbol
PARAMS ((char *));
172 void gdbtk_post_add_symbol
PARAMS ((void));
173 static int get_pc_register
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
174 static int gdb_loadfile
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
175 static int gdb_set_bp
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
176 static struct symtab
*full_lookup_symtab
PARAMS ((char *file
));
177 static int gdb_get_mem
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
179 static void gdbtk_annotate_starting
PARAMS ((void));
180 static void gdbtk_annotate_stopped
PARAMS ((void));
181 static void gdbtk_annotate_signalled
PARAMS ((void));
182 static void gdbtk_annotate_exited
PARAMS ((void));
185 /* Handle for TCL interpreter */
186 static Tcl_Interp
*interp
= NULL
;
189 static int x_fd
; /* X network socket */
194 /* On Windows we use timer interrupts when gdb might otherwise hang
195 for a long time. See the comment above gdbtk_start_timer. This
196 variable is true when timer interrupts are being used. */
198 static int gdbtk_timer_going
= 0;
200 static void gdbtk_start_timer
PARAMS ((void));
201 static void gdbtk_stop_timer
PARAMS ((void));
205 /* This variable is true when the inferior is running. Although it's
206 possible to disable most input from widgets and thus prevent
207 attempts to do anything while the inferior is running, any commands
208 that get through - even a simple memory read - are Very Bad, and
209 may cause GDB to crash or behave strangely. So, this variable
210 provides an extra layer of defense. */
212 static int running_now
;
214 /* This variable determines where memory used for disassembly is read from.
215 If > 0, then disassembly comes from the exec file rather than the
216 target (which might be at the other end of a slow serial link). If
217 == 0 then disassembly comes from target. If < 0 disassembly is
218 automatically switched to the target if it's an inferior process,
219 otherwise the exec file is used. */
221 static int disassemble_from_exec
= -1;
225 /* Supply malloc calls for tcl/tk. We do not want to do this on
226 Windows, because Tcl_Alloc is probably in a DLL which will not call
227 the mmalloc routines. */
233 return xmalloc (size
);
237 Tcl_Realloc (ptr
, size
)
241 return xrealloc (ptr
, size
);
251 #endif /* ! _WIN32 */
261 /* On Windows, if we hold a file open, other programs can't write to
262 it. In particular, we don't want to hold the executable open,
263 because it will mean that people have to get out of the debugging
264 session in order to remake their program. So we close it, although
265 this will cost us if and when we need to reopen it. */
275 bfd_cache_close (o
->obfd
);
278 if (exec_bfd
!= NULL
)
279 bfd_cache_close (exec_bfd
);
284 /* The following routines deal with stdout/stderr data, which is created by
285 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
286 lowest level of these routines and capture all output from the rest of GDB.
287 Normally they present their data to tcl via callbacks to the following tcl
288 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
289 in turn call tk routines to update the display.
291 Under some circumstances, you may want to collect the output so that it can
292 be returned as the value of a tcl procedure. This can be done by
293 surrounding the output routines with calls to start_saving_output and
294 finish_saving_output. The saved data can then be retrieved with
295 get_saved_output (but this must be done before the call to
296 finish_saving_output). */
298 /* Dynamic string for output. */
300 static Tcl_DString
*result_ptr
;
302 /* Dynamic string for stderr. This is only used if result_ptr is
305 static Tcl_DString
*error_string_ptr
;
312 /* Force immediate screen update */
314 Tcl_VarEval (interp
, "gdbtk_tcl_flush", NULL
);
319 gdbtk_fputs (ptr
, stream
)
323 char *merge
[2], *command
;
327 Tcl_DStringAppend (result_ptr
, (char *) ptr
, -1);
328 else if (error_string_ptr
!= NULL
&& stream
== gdb_stderr
)
329 Tcl_DStringAppend (error_string_ptr
, (char *) ptr
, -1);
332 merge
[0] = "gdbtk_tcl_fputs";
333 merge
[1] = (char *)ptr
;
334 command
= Tcl_Merge (2, merge
);
335 Tcl_Eval (interp
, command
);
342 gdbtk_query (query
, args
)
346 char buf
[200], *merge
[2];
350 vsprintf (buf
, query
, args
);
351 merge
[0] = "gdbtk_tcl_query";
353 command
= Tcl_Merge (2, merge
);
354 Tcl_Eval (interp
, command
);
357 val
= atol (interp
->result
);
363 #ifdef ANSI_PROTOTYPES
364 gdbtk_readline_begin (char *format
, ...)
366 gdbtk_readline_begin (va_alist
)
371 char buf
[200], *merge
[2];
374 #ifdef ANSI_PROTOTYPES
375 va_start (args
, format
);
379 format
= va_arg (args
, char *);
382 vsprintf (buf
, format
, args
);
383 merge
[0] = "gdbtk_tcl_readline_begin";
385 command
= Tcl_Merge (2, merge
);
386 Tcl_Eval (interp
, command
);
391 gdbtk_readline (prompt
)
402 merge
[0] = "gdbtk_tcl_readline";
404 command
= Tcl_Merge (2, merge
);
405 result
= Tcl_Eval (interp
, command
);
407 if (result
== TCL_OK
)
409 return (strdup (interp
-> result
));
413 gdbtk_fputs (interp
-> result
, gdb_stdout
);
414 gdbtk_fputs ("\n", gdb_stdout
);
420 gdbtk_readline_end ()
422 Tcl_Eval (interp
, "gdbtk_tcl_readline_end");
428 Tcl_Eval (interp
, "gdbtk_pc_changed");
433 #ifdef ANSI_PROTOTYPES
434 dsprintf_append_element (Tcl_DString
*dsp
, char *format
, ...)
436 dsprintf_append_element (va_alist
)
443 #ifdef ANSI_PROTOTYPES
444 va_start (args
, format
);
450 dsp
= va_arg (args
, Tcl_DString
*);
451 format
= va_arg (args
, char *);
454 vsprintf (buf
, format
, args
);
456 Tcl_DStringAppendElement (dsp
, buf
);
460 gdb_path_conv (clientData
, interp
, argc
, argv
)
461 ClientData clientData
;
467 char pathname
[256], *ptr
;
469 error ("wrong # args");
470 cygwin32_conv_to_full_win32_path (argv
[1], pathname
);
471 for (ptr
= pathname
; *ptr
; ptr
++)
477 char *pathname
= argv
[1];
479 Tcl_DStringAppend (result_ptr
, pathname
, strlen(pathname
));
484 gdb_get_breakpoint_list (clientData
, interp
, argc
, argv
)
485 ClientData clientData
;
490 struct breakpoint
*b
;
491 extern struct breakpoint
*breakpoint_chain
;
494 error ("wrong # args");
496 for (b
= breakpoint_chain
; b
; b
= b
->next
)
497 if (b
->type
== bp_breakpoint
)
498 dsprintf_append_element (result_ptr
, "%d", b
->number
);
504 gdb_get_breakpoint_info (clientData
, interp
, argc
, argv
)
505 ClientData clientData
;
510 struct symtab_and_line sal
;
511 static char *bptypes
[] = {"breakpoint", "hardware breakpoint", "until",
512 "finish", "watchpoint", "hardware watchpoint",
513 "read watchpoint", "access watchpoint",
514 "longjmp", "longjmp resume", "step resume",
515 "through sigtramp", "watchpoint scope",
517 static char *bpdisp
[] = {"delete", "delstop", "disable", "donttouch"};
518 struct command_line
*cmd
;
520 struct breakpoint
*b
;
521 extern struct breakpoint
*breakpoint_chain
;
522 char *funcname
, *fname
, *filename
;
525 error ("wrong # args");
527 bpnum
= atoi (argv
[1]);
529 for (b
= breakpoint_chain
; b
; b
= b
->next
)
530 if (b
->number
== bpnum
)
533 if (!b
|| b
->type
!= bp_breakpoint
)
534 error ("Breakpoint #%d does not exist", bpnum
);
536 sal
= find_pc_line (b
->address
, 0);
538 filename
= symtab_to_filename (sal
.symtab
);
539 if (filename
== NULL
)
541 Tcl_DStringAppendElement (result_ptr
, filename
);
543 find_pc_partial_function (b
->address
, &funcname
, NULL
, NULL
);
544 fname
= cplus_demangle (funcname
, 0);
547 Tcl_DStringAppendElement (result_ptr
, fname
);
551 Tcl_DStringAppendElement (result_ptr
, funcname
);
552 dsprintf_append_element (result_ptr
, "%d", b
->line_number
);
553 dsprintf_append_element (result_ptr
, "0x%lx", b
->address
);
554 Tcl_DStringAppendElement (result_ptr
, bptypes
[b
->type
]);
555 Tcl_DStringAppendElement (result_ptr
, b
->enable
== enabled
? "1" : "0");
556 Tcl_DStringAppendElement (result_ptr
, bpdisp
[b
->disposition
]);
557 dsprintf_append_element (result_ptr
, "%d", b
->ignore_count
);
559 Tcl_DStringStartSublist (result_ptr
);
560 for (cmd
= b
->commands
; cmd
; cmd
= cmd
->next
)
561 Tcl_DStringAppendElement (result_ptr
, cmd
->line
);
562 Tcl_DStringEndSublist (result_ptr
);
564 Tcl_DStringAppendElement (result_ptr
, b
->cond_string
);
566 dsprintf_append_element (result_ptr
, "%d", b
->thread
);
567 dsprintf_append_element (result_ptr
, "%d", b
->hit_count
);
573 breakpoint_notify(b
, action
)
574 struct breakpoint
*b
;
579 struct symtab_and_line sal
;
582 if (b
->type
!= bp_breakpoint
)
585 /* We ensure that ACTION contains no special Tcl characters, so we
587 sal
= find_pc_line (b
->address
, 0);
588 filename
= symtab_to_filename (sal
.symtab
);
589 if (filename
== NULL
)
592 sprintf (buf
, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action
, b
->number
,
593 (long)b
->address
, b
->line_number
, filename
);
595 v
= Tcl_Eval (interp
, buf
);
599 gdbtk_fputs (interp
->result
, gdb_stdout
);
600 gdbtk_fputs ("\n", gdb_stdout
);
605 gdbtk_create_breakpoint(b
)
606 struct breakpoint
*b
;
608 breakpoint_notify (b
, "create");
612 gdbtk_delete_breakpoint(b
)
613 struct breakpoint
*b
;
615 breakpoint_notify (b
, "delete");
619 gdbtk_modify_breakpoint(b
)
620 struct breakpoint
*b
;
622 breakpoint_notify (b
, "modify");
625 /* This implements the TCL command `gdb_loc', which returns a list */
626 /* consisting of the following: */
627 /* basename, function name, filename, line number, address, current pc */
630 gdb_loc (clientData
, interp
, argc
, argv
)
631 ClientData clientData
;
637 struct symtab_and_line sal
;
638 char *funcname
, *fname
;
641 if (!have_full_symbols () && !have_partial_symbols ())
643 Tcl_SetResult (interp
, "No symbol table is loaded", TCL_STATIC
);
649 if (selected_frame
&& (selected_frame
->pc
!= stop_pc
))
651 /* Note - this next line is not correct on all architectures. */
652 /* For a graphical debugged we really want to highlight the */
653 /* assembly line that called the next function on the stack. */
654 /* Many architectures have the next instruction saved as the */
655 /* pc on the stack, so what happens is the next instruction is hughlighted. */
657 pc
= selected_frame
->pc
;
658 sal
= find_pc_line (selected_frame
->pc
,
659 selected_frame
->next
!= NULL
660 && !selected_frame
->next
->signal_handler_caller
661 && !frame_in_dummy (selected_frame
->next
));
666 sal
= find_pc_line (stop_pc
, 0);
671 struct symtabs_and_lines sals
;
674 sals
= decode_line_spec (argv
[1], 1);
681 error ("Ambiguous line spec");
686 error ("wrong # args");
689 Tcl_DStringAppendElement (result_ptr
, sal
.symtab
->filename
);
691 Tcl_DStringAppendElement (result_ptr
, "");
693 find_pc_partial_function (pc
, &funcname
, NULL
, NULL
);
694 fname
= cplus_demangle (funcname
, 0);
697 Tcl_DStringAppendElement (result_ptr
, fname
);
701 Tcl_DStringAppendElement (result_ptr
, funcname
);
702 filename
= symtab_to_filename (sal
.symtab
);
703 if (filename
== NULL
)
706 Tcl_DStringAppendElement (result_ptr
, filename
);
707 dsprintf_append_element (result_ptr
, "%d", sal
.line
); /* line number */
708 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(pc
)); /* PC in current frame */
709 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(stop_pc
)); /* Real PC */
713 /* This implements the TCL command `gdb_eval'. */
716 gdb_eval (clientData
, interp
, argc
, argv
)
717 ClientData clientData
;
722 struct expression
*expr
;
723 struct cleanup
*old_chain
;
727 error ("wrong # args");
729 expr
= parse_expression (argv
[1]);
731 old_chain
= make_cleanup (free_current_contents
, &expr
);
733 val
= evaluate_expression (expr
);
735 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
736 gdb_stdout
, 0, 0, 0, 0);
738 do_cleanups (old_chain
);
743 /* gdb_get_mem addr form size num aschar*/
744 /* dump a block of memory */
745 /* addr: address of data to dump */
746 /* form: a char indicating format */
747 /* size: size of each element; 1,2,4, or 8 bytes*/
748 /* num: the number of bytes to read */
749 /* acshar: an optional ascii character to use in ASCII dump */
750 /* returns a list of elements followed by an optional */
754 gdb_get_mem (clientData
, interp
, argc
, argv
)
755 ClientData clientData
;
760 int size
, asize
, i
, j
, bc
;
762 int nbytes
, rnum
, bpr
;
763 char format
, c
, *ptr
, buff
[128], aschar
, *mbuf
, *mptr
, *cptr
, *bptr
;
764 struct type
*val_type
;
766 if (argc
< 6 || argc
> 7)
768 interp
->result
= "addr format size bytes bytes_per_row ?ascii_char?";
772 size
= (int)strtoul(argv
[3],(char **)NULL
,0);
773 nbytes
= (int)strtoul(argv
[4],(char **)NULL
,0);
774 bpr
= (int)strtoul(argv
[5],(char **)NULL
,0);
775 if (nbytes
<= 0 || bpr
<= 0 || size
<= 0)
777 interp
->result
= "Invalid number of bytes.";
781 addr
= (CORE_ADDR
)strtoul(argv
[1],(char **)NULL
,0);
783 mbuf
= (char *)malloc (nbytes
+32);
786 interp
->result
= "Out of memory.";
789 memset (mbuf
, 0, nbytes
+32);
792 rnum
= target_read_memory_partial (addr
, mbuf
, nbytes
, NULL
);
801 val_type
= builtin_type_char
;
805 val_type
= builtin_type_short
;
809 val_type
= builtin_type_int
;
813 val_type
= builtin_type_long_long
;
817 val_type
= builtin_type_char
;
821 bc
= 0; /* count of bytes in a row */
822 buff
[0] = '"'; /* buffer for ascii dump */
823 bptr
= &buff
[1]; /* pointer for ascii dump */
825 for (i
=0; i
< nbytes
; i
+= size
)
829 fputs_unfiltered ("N/A ", gdb_stdout
);
831 for ( j
= 0; j
< size
; j
++)
836 print_scalar_formatted (mptr
, val_type
, format
, asize
, gdb_stdout
);
837 fputs_unfiltered (" ", gdb_stdout
);
840 for ( j
= 0; j
< size
; j
++)
843 if (c
< 32 || c
> 126)
855 if (aschar
&& (bc
>= bpr
))
857 /* end of row. print it and reset variables */
862 fputs_unfiltered (buff
, gdb_stdout
);
872 map_arg_registers (argc
, argv
, func
, argp
)
875 void (*func
) PARAMS ((int regnum
, void *argp
));
880 /* Note that the test for a valid register must include checking the
881 reg_names array because NUM_REGS may be allocated for the union of the
882 register sets within a family of related processors. In this case, the
883 trailing entries of reg_names will change depending upon the particular
884 processor being debugged. */
886 if (argc
== 0) /* No args, just do all the regs */
890 && reg_names
[regnum
] != NULL
891 && *reg_names
[regnum
] != '\000';
898 /* Else, list of register #s, just do listed regs */
899 for (; argc
> 0; argc
--, argv
++)
901 regnum
= atoi (*argv
);
905 && reg_names
[regnum
] != NULL
906 && *reg_names
[regnum
] != '\000')
909 error ("bad register number");
916 get_register_name (regnum
, argp
)
918 void *argp
; /* Ignored */
920 Tcl_DStringAppendElement (result_ptr
, reg_names
[regnum
]);
923 /* This implements the TCL command `gdb_regnames', which returns a list of
924 all of the register names. */
927 gdb_regnames (clientData
, interp
, argc
, argv
)
928 ClientData clientData
;
936 return map_arg_registers (argc
, argv
, get_register_name
, NULL
);
939 #ifndef REGISTER_CONVERTIBLE
940 #define REGISTER_CONVERTIBLE(x) (0 != 0)
943 #ifndef REGISTER_CONVERT_TO_VIRTUAL
944 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
947 #ifndef INVALID_FLOAT
948 #define INVALID_FLOAT(x, y) (0 != 0)
952 get_register (regnum
, fp
)
956 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
957 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
958 int format
= (int)fp
;
963 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
965 Tcl_DStringAppendElement (result_ptr
, "Optimized out");
969 /* Convert raw data to virtual format if necessary. */
971 if (REGISTER_CONVERTIBLE (regnum
))
973 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
974 raw_buffer
, virtual_buffer
);
977 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
982 printf_filtered ("0x");
983 for (j
= 0; j
< REGISTER_RAW_SIZE (regnum
); j
++)
985 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
986 : REGISTER_RAW_SIZE (regnum
) - 1 - j
;
987 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
991 val_print (REGISTER_VIRTUAL_TYPE (regnum
), virtual_buffer
, 0,
992 gdb_stdout
, format
, 1, 0, Val_pretty_default
);
994 Tcl_DStringAppend (result_ptr
, " ", -1);
998 get_pc_register (clientData
, interp
, argc
, argv
)
999 ClientData clientData
;
1004 sprintf(interp
->result
,"0x%llx",(long long)read_register(PC_REGNUM
));
1009 gdb_fetch_registers (clientData
, interp
, argc
, argv
)
1010 ClientData clientData
;
1018 error ("wrong # args");
1024 return map_arg_registers (argc
, argv
, get_register
, (void *) format
);
1027 /* This contains the previous values of the registers, since the last call to
1028 gdb_changed_register_list. */
1030 static char old_regs
[REGISTER_BYTES
];
1033 register_changed_p (regnum
, argp
)
1035 void *argp
; /* Ignored */
1037 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
1039 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
1042 if (memcmp (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
1043 REGISTER_RAW_SIZE (regnum
)) == 0)
1046 /* Found a changed register. Save new value and return its number. */
1048 memcpy (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
1049 REGISTER_RAW_SIZE (regnum
));
1051 dsprintf_append_element (result_ptr
, "%d", regnum
);
1055 gdb_changed_register_list (clientData
, interp
, argc
, argv
)
1056 ClientData clientData
;
1064 return map_arg_registers (argc
, argv
, register_changed_p
, NULL
);
1067 /* This implements the tcl command "gdb_immediate", which does exactly
1068 the same thing as gdb_cmd, except NONE of its outut is buffered. */
1069 /* This will also ALWAYS cause the busy,update, and idle hooks to be
1070 called, contrasted with gdb_cmd, which NEVER calls them. */
1072 gdb_immediate_command (clientData
, interp
, argc
, argv
)
1073 ClientData clientData
;
1078 Tcl_DString
*save_ptr
= NULL
;
1081 error ("wrong # args");
1083 if (running_now
|| load_in_progress
)
1088 Tcl_DStringAppend (result_ptr
, "", -1);
1089 save_ptr
= result_ptr
;
1092 execute_command (argv
[1], 1);
1094 bpstat_do_actions (&stop_bpstat
);
1096 result_ptr
= save_ptr
;
1101 /* This implements the TCL command `gdb_cmd', which sends its argument into
1102 the GDB command scanner. */
1103 /* This command will never cause the update, idle and busy hooks to be called
1106 gdb_cmd (clientData
, interp
, argc
, argv
)
1107 ClientData clientData
;
1112 Tcl_DString
*save_ptr
= NULL
;
1115 error ("wrong # args");
1117 if (running_now
|| load_in_progress
)
1122 /* for the load instruction (and possibly others later) we
1123 set result_ptr to NULL so gdbtk_fputs() will not buffer
1124 all the data until the command is finished. */
1126 if (strncmp ("load ", argv
[1], 5) == 0
1127 || strncmp ("while ", argv
[1], 6) == 0)
1129 Tcl_DStringAppend (result_ptr
, "", -1);
1130 save_ptr
= result_ptr
;
1132 load_in_progress
= 1;
1134 /* On Windows, use timer interrupts so that the user can cancel
1135 the download. FIXME: We may have to do something on other
1138 gdbtk_start_timer ();
1142 execute_command (argv
[1], 1);
1145 if (load_in_progress
)
1146 gdbtk_stop_timer ();
1149 load_in_progress
= 0;
1150 bpstat_do_actions (&stop_bpstat
);
1153 result_ptr
= save_ptr
;
1158 /* Client of call_wrapper - this routine performs the actual call to
1159 the client function. */
1161 struct wrapped_call_args
1172 struct wrapped_call_args
*args
;
1174 args
->val
= (*args
->func
) (args
->func
, args
->interp
, args
->argc
, args
->argv
);
1178 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
1179 handles cleanups, and calls to return_to_top_level (usually via error).
1180 This is necessary in order to prevent a longjmp out of the bowels of Tk,
1181 possibly leaving things in a bad state. Since this routine can be called
1182 recursively, it needs to save and restore the contents of the jmp_buf as
1186 call_wrapper (clientData
, interp
, argc
, argv
)
1187 ClientData clientData
;
1192 struct wrapped_call_args wrapped_args
;
1193 Tcl_DString result
, *old_result_ptr
;
1194 Tcl_DString error_string
, *old_error_string_ptr
;
1196 Tcl_DStringInit (&result
);
1197 old_result_ptr
= result_ptr
;
1198 result_ptr
= &result
;
1200 Tcl_DStringInit (&error_string
);
1201 old_error_string_ptr
= error_string_ptr
;
1202 error_string_ptr
= &error_string
;
1204 wrapped_args
.func
= (Tcl_CmdProc
*)clientData
;
1205 wrapped_args
.interp
= interp
;
1206 wrapped_args
.argc
= argc
;
1207 wrapped_args
.argv
= argv
;
1208 wrapped_args
.val
= 0;
1210 if (!catch_errors (wrapped_call
, &wrapped_args
, "", RETURN_MASK_ALL
))
1212 wrapped_args
.val
= TCL_ERROR
; /* Flag an error for TCL */
1215 /* Make sure the timer interrupts are turned off. */
1216 if (gdbtk_timer_going
)
1217 gdbtk_stop_timer ();
1220 gdb_flush (gdb_stderr
); /* Flush error output */
1221 gdb_flush (gdb_stdout
); /* Sometimes error output comes here as well */
1223 /* In case of an error, we may need to force the GUI into idle
1224 mode because gdbtk_call_command may have bombed out while in
1225 the command routine. */
1228 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1231 /* do not suppress any errors -- a remote target could have errored */
1232 load_in_progress
= 0;
1234 if (Tcl_DStringLength (&error_string
) == 0)
1236 Tcl_DStringResult (interp
, &result
);
1237 Tcl_DStringFree (&error_string
);
1239 else if (Tcl_DStringLength (&result
) == 0)
1241 Tcl_DStringResult (interp
, &error_string
);
1242 Tcl_DStringFree (&result
);
1243 Tcl_DStringFree (&error_string
);
1247 Tcl_ResetResult (interp
);
1248 Tcl_AppendResult (interp
, Tcl_DStringValue (&result
),
1249 Tcl_DStringValue (&error_string
), (char *) NULL
);
1250 Tcl_DStringFree (&result
);
1251 Tcl_DStringFree (&error_string
);
1254 result_ptr
= old_result_ptr
;
1255 error_string_ptr
= old_error_string_ptr
;
1261 return wrapped_args
.val
;
1265 comp_files (file1
, file2
)
1266 const char *file1
[], *file2
[];
1268 return strcmp(*file1
,*file2
);
1272 gdb_listfiles (clientData
, interp
, objc
, objv
)
1273 ClientData clientData
;
1276 Tcl_Obj
*CONST objv
[];
1278 struct objfile
*objfile
;
1279 struct partial_symtab
*psymtab
;
1280 struct symtab
*symtab
;
1281 char *lastfile
, *pathname
, **files
;
1283 int i
, numfiles
= 0, len
= 0;
1287 files
= (char **) xmalloc (sizeof (char *) * files_size
);
1291 Tcl_WrongNumArgs (interp
, 1, objv
, "Usage: gdb_listfiles ?pathname?");
1295 pathname
= Tcl_GetStringFromObj (objv
[1], &len
);
1297 mylist
= Tcl_NewListObj (0, NULL
);
1299 ALL_PSYMTABS (objfile
, psymtab
)
1301 if (numfiles
== files_size
)
1303 files_size
= files_size
* 2;
1304 files
= (char **) xrealloc (files
, sizeof (char *) * files_size
);
1308 if (psymtab
->filename
)
1309 files
[numfiles
++] = basename(psymtab
->filename
);
1311 else if (!strcmp(psymtab
->filename
,basename(psymtab
->filename
))
1312 || !strncmp(pathname
,psymtab
->filename
,len
))
1313 if (psymtab
->filename
)
1314 files
[numfiles
++] = basename(psymtab
->filename
);
1317 ALL_SYMTABS (objfile
, symtab
)
1319 if (numfiles
== files_size
)
1321 files_size
= files_size
* 2;
1322 files
= (char **) xrealloc (files
, sizeof (char *) * files_size
);
1326 if (symtab
->filename
)
1327 files
[numfiles
++] = basename(symtab
->filename
);
1329 else if (!strcmp(symtab
->filename
,basename(symtab
->filename
))
1330 || !strncmp(pathname
,symtab
->filename
,len
))
1331 if (symtab
->filename
)
1332 files
[numfiles
++] = basename(symtab
->filename
);
1335 qsort (files
, numfiles
, sizeof(char *), comp_files
);
1338 for (i
= 0; i
< numfiles
; i
++)
1340 if (strcmp(files
[i
],lastfile
))
1341 Tcl_ListObjAppendElement (interp
, mylist
, Tcl_NewStringObj(files
[i
], -1));
1342 lastfile
= files
[i
];
1344 Tcl_SetObjResult (interp
, mylist
);
1350 gdb_listfuncs (clientData
, interp
, argc
, argv
)
1351 ClientData clientData
;
1356 struct symtab
*symtab
;
1357 struct blockvector
*bv
;
1364 error ("wrong # args");
1366 symtab
= full_lookup_symtab (argv
[1]);
1368 error ("No such file");
1370 bv
= BLOCKVECTOR (symtab
);
1371 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
1373 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1374 /* Skip the sort if this block is always sorted. */
1375 if (!BLOCK_SHOULD_SORT (b
))
1376 sort_block_syms (b
);
1377 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
1379 sym
= BLOCK_SYM (b
, j
);
1380 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1383 char *name
= cplus_demangle (SYMBOL_NAME(sym
), 0);
1386 sprintf (buf
,"{%s} 1", name
);
1389 sprintf (buf
,"{%s} 0", SYMBOL_NAME(sym
));
1390 Tcl_DStringAppendElement (result_ptr
, buf
);
1398 target_stop_wrapper (args
)
1406 gdb_stop (clientData
, interp
, argc
, argv
)
1407 ClientData clientData
;
1414 catch_errors (target_stop_wrapper
, NULL
, "",
1418 quit_flag
= 1; /* hope something sees this */
1423 /* Prepare to accept a new executable file. This is called when we
1424 want to clear away everything we know about the old file, without
1425 asking the user. The Tcl code will have already asked the user if
1426 necessary. After this is called, we should be able to run the
1427 `file' command without getting any questions. */
1430 gdb_clear_file (clientData
, interp
, argc
, argv
)
1431 ClientData clientData
;
1436 if (inferior_pid
!= 0 && target_has_execution
)
1439 target_detach (NULL
, 0);
1444 if (target_has_execution
)
1447 symbol_file_command (NULL
, 0);
1449 /* gdb_loc refers to stop_pc, but nothing seems to clear it, so we
1450 clear it here. FIXME: This seems like an abstraction violation
1457 /* Ask the user to confirm an exit request. */
1460 gdb_confirm_quit (clientData
, interp
, argc
, argv
)
1461 ClientData clientData
;
1468 ret
= quit_confirm ();
1469 Tcl_DStringAppendElement (result_ptr
, ret
? "1" : "0");
1473 /* Quit without asking for confirmation. */
1476 gdb_force_quit (clientData
, interp
, argc
, argv
)
1477 ClientData clientData
;
1482 quit_force ((char *) NULL
, 1);
1486 /* This implements the TCL command `gdb_disassemble'. */
1489 gdbtk_dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
1493 disassemble_info
*info
;
1495 extern struct target_ops exec_ops
;
1499 res
= xfer_memory (memaddr
, myaddr
, len
, 0, &exec_ops
);
1510 /* We need a different sort of line table from the normal one cuz we can't
1511 depend upon implicit line-end pc's for lines. This is because of the
1512 reordering we are about to do. */
1514 struct my_line_entry
{
1521 compare_lines (mle1p
, mle2p
)
1525 struct my_line_entry
*mle1
, *mle2
;
1528 mle1
= (struct my_line_entry
*) mle1p
;
1529 mle2
= (struct my_line_entry
*) mle2p
;
1531 val
= mle1
->line
- mle2
->line
;
1536 return mle1
->start_pc
- mle2
->start_pc
;
1540 gdb_disassemble (clientData
, interp
, argc
, argv
)
1541 ClientData clientData
;
1546 CORE_ADDR pc
, low
, high
;
1547 int mixed_source_and_assembly
;
1548 static disassemble_info di
;
1549 static int di_initialized
;
1551 if (! di_initialized
)
1553 INIT_DISASSEMBLE_INFO_NO_ARCH (di
, gdb_stdout
,
1554 (fprintf_ftype
) fprintf_unfiltered
);
1555 di
.flavour
= bfd_target_unknown_flavour
;
1556 di
.memory_error_func
= dis_asm_memory_error
;
1557 di
.print_address_func
= dis_asm_print_address
;
1561 di
.mach
= tm_print_insn_info
.mach
;
1562 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1563 di
.endian
= BFD_ENDIAN_BIG
;
1565 di
.endian
= BFD_ENDIAN_LITTLE
;
1567 if (argc
!= 3 && argc
!= 4)
1568 error ("wrong # args");
1570 if (strcmp (argv
[1], "source") == 0)
1571 mixed_source_and_assembly
= 1;
1572 else if (strcmp (argv
[1], "nosource") == 0)
1573 mixed_source_and_assembly
= 0;
1575 error ("First arg must be 'source' or 'nosource'");
1577 low
= parse_and_eval_address (argv
[2]);
1581 if (find_pc_partial_function (low
, NULL
, &low
, &high
) == 0)
1582 error ("No function contains specified address");
1585 high
= parse_and_eval_address (argv
[3]);
1587 /* If disassemble_from_exec == -1, then we use the following heuristic to
1588 determine whether or not to do disassembly from target memory or from the
1591 If we're debugging a local process, read target memory, instead of the
1592 exec file. This makes disassembly of functions in shared libs work
1595 Else, we're debugging a remote process, and should disassemble from the
1596 exec file for speed. However, this is no good if the target modifies its
1597 code (for relocation, or whatever).
1600 if (disassemble_from_exec
== -1)
1601 if (strcmp (target_shortname
, "child") == 0
1602 || strcmp (target_shortname
, "procfs") == 0
1603 || strcmp (target_shortname
, "vxprocess") == 0)
1604 disassemble_from_exec
= 0; /* It's a child process, read inferior mem */
1606 disassemble_from_exec
= 1; /* It's remote, read the exec file */
1608 if (disassemble_from_exec
)
1609 di
.read_memory_func
= gdbtk_dis_asm_read_memory
;
1611 di
.read_memory_func
= dis_asm_read_memory
;
1613 /* If just doing straight assembly, all we need to do is disassemble
1614 everything between low and high. If doing mixed source/assembly, we've
1615 got a totally different path to follow. */
1617 if (mixed_source_and_assembly
)
1618 { /* Come here for mixed source/assembly */
1619 /* The idea here is to present a source-O-centric view of a function to
1620 the user. This means that things are presented in source order, with
1621 (possibly) out of order assembly immediately following. */
1622 struct symtab
*symtab
;
1623 struct linetable_entry
*le
;
1626 struct my_line_entry
*mle
;
1627 struct symtab_and_line sal
;
1632 symtab
= find_pc_symtab (low
); /* Assume symtab is valid for whole PC range */
1637 /* First, convert the linetable to a bunch of my_line_entry's. */
1639 le
= symtab
->linetable
->item
;
1640 nlines
= symtab
->linetable
->nitems
;
1645 mle
= (struct my_line_entry
*) alloca (nlines
* sizeof (struct my_line_entry
));
1649 /* Copy linetable entries for this function into our data structure, creating
1650 end_pc's and setting out_of_order as appropriate. */
1652 /* First, skip all the preceding functions. */
1654 for (i
= 0; i
< nlines
- 1 && le
[i
].pc
< low
; i
++) ;
1656 /* Now, copy all entries before the end of this function. */
1659 for (; i
< nlines
- 1 && le
[i
].pc
< high
; i
++)
1661 if (le
[i
].line
== le
[i
+ 1].line
1662 && le
[i
].pc
== le
[i
+ 1].pc
)
1663 continue; /* Ignore duplicates */
1665 mle
[newlines
].line
= le
[i
].line
;
1666 if (le
[i
].line
> le
[i
+ 1].line
)
1668 mle
[newlines
].start_pc
= le
[i
].pc
;
1669 mle
[newlines
].end_pc
= le
[i
+ 1].pc
;
1673 /* If we're on the last line, and it's part of the function, then we need to
1674 get the end pc in a special way. */
1679 mle
[newlines
].line
= le
[i
].line
;
1680 mle
[newlines
].start_pc
= le
[i
].pc
;
1681 sal
= find_pc_line (le
[i
].pc
, 0);
1682 mle
[newlines
].end_pc
= sal
.end
;
1686 /* Now, sort mle by line #s (and, then by addresses within lines). */
1689 qsort (mle
, newlines
, sizeof (struct my_line_entry
), compare_lines
);
1691 /* Now, for each line entry, emit the specified lines (unless they have been
1692 emitted before), followed by the assembly code for that line. */
1694 next_line
= 0; /* Force out first line */
1695 for (i
= 0; i
< newlines
; i
++)
1697 /* Print out everything from next_line to the current line. */
1699 if (mle
[i
].line
>= next_line
)
1702 print_source_lines (symtab
, next_line
, mle
[i
].line
+ 1, 0);
1704 print_source_lines (symtab
, mle
[i
].line
, mle
[i
].line
+ 1, 0);
1706 next_line
= mle
[i
].line
+ 1;
1709 for (pc
= mle
[i
].start_pc
; pc
< mle
[i
].end_pc
; )
1712 fputs_unfiltered (" ", gdb_stdout
);
1713 print_address (pc
, gdb_stdout
);
1714 fputs_unfiltered (":\t ", gdb_stdout
);
1715 pc
+= (*tm_print_insn
) (pc
, &di
);
1716 fputs_unfiltered ("\n", gdb_stdout
);
1723 for (pc
= low
; pc
< high
; )
1726 fputs_unfiltered (" ", gdb_stdout
);
1727 print_address (pc
, gdb_stdout
);
1728 fputs_unfiltered (":\t ", gdb_stdout
);
1729 pc
+= (*tm_print_insn
) (pc
, &di
);
1730 fputs_unfiltered ("\n", gdb_stdout
);
1734 gdb_flush (gdb_stdout
);
1740 tk_command (cmd
, from_tty
)
1746 struct cleanup
*old_chain
;
1748 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
1750 error_no_arg ("tcl command to interpret");
1752 retval
= Tcl_Eval (interp
, cmd
);
1754 result
= strdup (interp
->result
);
1756 old_chain
= make_cleanup (free
, result
);
1758 if (retval
!= TCL_OK
)
1761 printf_unfiltered ("%s\n", result
);
1763 do_cleanups (old_chain
);
1767 cleanup_init (ignored
)
1771 Tcl_DeleteInterp (interp
);
1775 /* Come here during long calculations to check for GUI events. Usually invoked
1776 via the QUIT macro. */
1779 gdbtk_interactive ()
1781 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1784 /* Come here when there is activity on the X file descriptor. */
1790 static int in_x_event
= 0;
1791 static Tcl_Obj
*varname
= NULL
;
1793 if (in_x_event
|| in_fputs
)
1798 /* Process pending events */
1799 while (Tcl_DoOneEvent (TCL_DONT_WAIT
|TCL_ALL_EVENTS
) != 0)
1802 if (load_in_progress
)
1805 if (varname
== NULL
)
1807 Tcl_Obj
*varnamestrobj
= Tcl_NewStringObj("download_cancel_ok",-1);
1808 varname
= Tcl_ObjGetVar2(interp
,varnamestrobj
,NULL
,TCL_GLOBAL_ONLY
);
1810 if ((Tcl_GetIntFromObj(interp
,varname
,&val
) == TCL_OK
) && val
)
1826 /* For Cygwin32, we use a timer to periodically check for Windows
1827 messages. FIXME: It would be better to not poll, but to instead
1828 rewrite the target_wait routines to serve as input sources.
1829 Unfortunately, that will be a lot of work. */
1830 static sigset_t nullsigmask
;
1831 static struct sigaction act1
, act2
;
1832 static struct itimerval it_on
, it_off
;
1835 gdbtk_start_timer ()
1837 static int first
= 1;
1838 /*TclDebug ("Starting timer....");*/
1841 /* first time called, set up all the structs */
1843 sigemptyset (&nullsigmask
);
1845 act1
.sa_handler
= x_event
;
1846 act1
.sa_mask
= nullsigmask
;
1849 act2
.sa_handler
= SIG_IGN
;
1850 act2
.sa_mask
= nullsigmask
;
1853 it_on
.it_interval
.tv_sec
= 0;
1854 it_on
.it_interval
.tv_usec
= 500000; /* .5 sec */
1855 it_on
.it_value
.tv_sec
= 0;
1856 it_on
.it_value
.tv_usec
= 500000;
1858 it_off
.it_interval
.tv_sec
= 0;
1859 it_off
.it_interval
.tv_usec
= 0;
1860 it_off
.it_value
.tv_sec
= 0;
1861 it_off
.it_value
.tv_usec
= 0;
1863 sigaction (SIGALRM
, &act1
, NULL
);
1864 setitimer (ITIMER_REAL
, &it_on
, NULL
);
1865 gdbtk_timer_going
= 1;
1871 gdbtk_timer_going
= 0;
1872 /*TclDebug ("Stopping timer.");*/
1873 setitimer (ITIMER_REAL
, &it_off
, NULL
);
1874 sigaction (SIGALRM
, &act2
, NULL
);
1879 /* This hook function is called whenever we want to wait for the
1883 gdbtk_wait (pid
, ourstatus
)
1885 struct target_waitstatus
*ourstatus
;
1888 struct sigaction action
;
1889 static sigset_t nullsigmask
= {0};
1893 /* Needed for SunOS 4.1.x */
1894 #define SA_RESTART 0
1897 action
.sa_handler
= x_event
;
1898 action
.sa_mask
= nullsigmask
;
1899 action
.sa_flags
= SA_RESTART
;
1900 sigaction(SIGIO
, &action
, NULL
);
1903 pid
= target_wait (pid
, ourstatus
);
1906 action
.sa_handler
= SIG_IGN
;
1907 sigaction(SIGIO
, &action
, NULL
);
1913 /* This is called from execute_command, and provides a wrapper around
1914 various command routines in a place where both protocol messages and
1915 user input both flow through. Mostly this is used for indicating whether
1916 the target process is running or not.
1920 gdbtk_call_command (cmdblk
, arg
, from_tty
)
1921 struct cmd_list_element
*cmdblk
;
1926 if (cmdblk
->class == class_run
|| cmdblk
->class == class_trace
)
1930 Tcl_Eval (interp
, "gdbtk_tcl_busy");
1931 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1934 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1937 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1940 /* This function is called instead of gdb's internal command loop. This is the
1941 last chance to do anything before entering the main Tk event loop. */
1946 extern GDB_FILE
*instream
;
1948 /* We no longer want to use stdin as the command input stream */
1951 if (Tcl_Eval (interp
, "gdbtk_tcl_preloop") != TCL_OK
)
1955 /* Force errorInfo to be set up propertly. */
1956 Tcl_AddErrorInfo (interp
, "");
1958 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
1960 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
1962 fputs_unfiltered (msg
, gdb_stderr
);
1973 /* gdbtk_init installs this function as a final cleanup. */
1976 gdbtk_cleanup (dummy
)
1980 struct ide_event_handle
*h
= (struct ide_event_handle
*) dummy
;
1982 ide_interface_deregister_all (h
);
1987 /* Initialize gdbtk. */
1990 gdbtk_init ( argv0
)
1993 struct cleanup
*old_chain
;
1994 char *lib
, *gdbtk_lib
, *gdbtk_lib_tmp
, *gdbtk_file
;
1997 struct sigaction action
;
1998 static sigset_t nullsigmask
= {0};
2001 /* start-sanitize-ide */
2002 struct ide_event_handle
*h
;
2005 /* end-sanitize-ide */
2008 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
2009 causing gdb to abort. If instead we simply return here, gdb will
2010 gracefully degrade to using the command line interface. */
2013 if (getenv ("DISPLAY") == NULL
)
2017 old_chain
= make_cleanup (cleanup_init
, 0);
2019 /* First init tcl and tk. */
2020 Tcl_FindExecutable (argv0
);
2021 interp
= Tcl_CreateInterp ();
2023 #ifdef TCL_MEM_DEBUG
2024 Tcl_InitMemory (interp
);
2028 error ("Tcl_CreateInterp failed");
2030 if (Tcl_Init(interp
) != TCL_OK
)
2031 error ("Tcl_Init failed: %s", interp
->result
);
2034 /* For the IDE we register the cleanup later, after we've
2035 initialized events. */
2036 make_final_cleanup (gdbtk_cleanup
, NULL
);
2039 /* Initialize the Paths variable. */
2040 if (ide_initialize_paths (interp
, "gdbtcl") != TCL_OK
)
2041 error ("ide_initialize_paths failed: %s", interp
->result
);
2044 /* start-sanitize-ide */
2045 /* Find the directory where we expect to find idemanager. We ignore
2046 errors since it doesn't really matter if this fails. */
2047 libexecdir
= Tcl_GetVar2 (interp
, "Paths", "libexecdir", TCL_GLOBAL_ONLY
);
2051 h
= ide_event_init_from_environment (&errmsg
, libexecdir
);
2052 make_final_cleanup (gdbtk_cleanup
, h
);
2055 Tcl_AppendResult (interp
, "can't initialize event system: ", errmsg
,
2057 fprintf(stderr
, "WARNING: ide_event_init_client failed: %s\n", interp
->result
);
2059 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
2063 if (ide_create_tclevent_command (interp
, h
) != TCL_OK
)
2064 error ("ide_create_tclevent_command failed: %s", interp
->result
);
2066 if (ide_create_edit_command (interp
, h
) != TCL_OK
)
2067 error ("ide_create_edit_command failed: %s", interp
->result
);
2069 if (ide_create_property_command (interp
, h
) != TCL_OK
)
2070 error ("ide_create_property_command failed: %s", interp
->result
);
2072 if (ide_create_build_command (interp
, h
) != TCL_OK
)
2073 error ("ide_create_build_command failed: %s", interp
->result
);
2075 if (ide_create_window_register_command (interp
, h
, "gdb-restore")
2077 error ("ide_create_window_register_command failed: %s",
2080 if (ide_create_window_command (interp
, h
) != TCL_OK
)
2081 error ("ide_create_window_command failed: %s", interp
->result
);
2083 if (ide_create_exit_command (interp
, h
) != TCL_OK
)
2084 error ("ide_create_exit_command failed: %s", interp
->result
);
2086 if (ide_create_help_command (interp
) != TCL_OK
)
2087 error ("ide_create_help_command failed: %s", interp
->result
);
2090 if (ide_initialize (interp, "gdb") != TCL_OK)
2091 error ("ide_initialize failed: %s", interp->result);
2094 Tcl_SetVar (interp
, "GDBTK_IDE", "1", 0);
2096 /* end-sanitize-ide */
2098 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
2101 /* We don't want to open the X connection until we've done all the
2102 IDE initialization. Otherwise, goofy looking unfinished windows
2103 pop up when ILU drops into the TCL event loop. */
2105 if (Tk_Init(interp
) != TCL_OK
)
2106 error ("Tk_Init failed: %s", interp
->result
);
2108 if (Itcl_Init(interp
) == TCL_ERROR
)
2109 error ("Itcl_Init failed: %s", interp
->result
);
2111 if (Tix_Init(interp
) != TCL_OK
)
2112 error ("Tix_Init failed: %s", interp
->result
);
2115 if (ide_create_messagebox_command (interp
) != TCL_OK
)
2116 error ("messagebox command initialization failed");
2117 /* On Windows, create a sizebox widget command */
2118 if (ide_create_sizebox_command (interp
) != TCL_OK
)
2119 error ("sizebox creation failed");
2120 if (ide_create_winprint_command (interp
) != TCL_OK
)
2121 error ("windows print code initialization failed");
2122 /* start-sanitize-ide */
2123 /* An interface to ShellExecute. */
2124 if (ide_create_shell_execute_command (interp
) != TCL_OK
)
2125 error ("shell execute command initialization failed");
2126 /* end-sanitize-ide */
2127 if (ide_create_win_grab_command (interp
) != TCL_OK
)
2128 error ("grab support command initialization failed");
2129 /* Path conversion functions. */
2130 if (ide_create_cygwin_path_command (interp
) != TCL_OK
)
2131 error ("cygwin path command initialization failed");
2134 Tcl_CreateCommand (interp
, "gdb_cmd", call_wrapper
, gdb_cmd
, NULL
);
2135 Tcl_CreateCommand (interp
, "gdb_immediate", call_wrapper
,
2136 gdb_immediate_command
, NULL
);
2137 Tcl_CreateCommand (interp
, "gdb_loc", call_wrapper
, gdb_loc
, NULL
);
2138 Tcl_CreateCommand (interp
, "gdb_path_conv", call_wrapper
, gdb_path_conv
, NULL
);
2139 Tcl_CreateObjCommand (interp
, "gdb_listfiles", gdb_listfiles
, NULL
, NULL
);
2140 Tcl_CreateCommand (interp
, "gdb_listfuncs", call_wrapper
, gdb_listfuncs
,
2142 Tcl_CreateCommand (interp
, "gdb_get_mem", call_wrapper
, gdb_get_mem
,
2144 Tcl_CreateCommand (interp
, "gdb_stop", call_wrapper
, gdb_stop
, NULL
);
2145 Tcl_CreateCommand (interp
, "gdb_regnames", call_wrapper
, gdb_regnames
, NULL
);
2146 Tcl_CreateCommand (interp
, "gdb_fetch_registers", call_wrapper
,
2147 gdb_fetch_registers
, NULL
);
2148 Tcl_CreateCommand (interp
, "gdb_changed_register_list", call_wrapper
,
2149 gdb_changed_register_list
, NULL
);
2150 Tcl_CreateCommand (interp
, "gdb_disassemble", call_wrapper
,
2151 gdb_disassemble
, NULL
);
2152 Tcl_CreateCommand (interp
, "gdb_eval", call_wrapper
, gdb_eval
, NULL
);
2153 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_list", call_wrapper
,
2154 gdb_get_breakpoint_list
, NULL
);
2155 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_info", call_wrapper
,
2156 gdb_get_breakpoint_info
, NULL
);
2157 Tcl_CreateCommand (interp
, "gdb_clear_file", call_wrapper
,
2158 gdb_clear_file
, NULL
);
2159 Tcl_CreateCommand (interp
, "gdb_confirm_quit", call_wrapper
,
2160 gdb_confirm_quit
, NULL
);
2161 Tcl_CreateCommand (interp
, "gdb_force_quit", call_wrapper
,
2162 gdb_force_quit
, NULL
);
2163 Tcl_CreateCommand (interp
, "gdb_target_has_execution",
2164 gdb_target_has_execution_command
,
2166 Tcl_CreateCommand (interp
, "gdb_is_tracing",
2169 Tcl_CreateObjCommand (interp
, "gdb_load_info", gdb_load_info
, NULL
, NULL
);
2170 Tcl_CreateObjCommand (interp
, "gdb_get_locals", gdb_get_vars_command
,
2171 (ClientData
) 0, NULL
);
2172 Tcl_CreateObjCommand (interp
, "gdb_get_args", gdb_get_vars_command
,
2173 (ClientData
) 1, NULL
);
2174 Tcl_CreateObjCommand (interp
, "gdb_get_function", gdb_get_function_command
,
2176 Tcl_CreateObjCommand (interp
, "gdb_get_line", gdb_get_line_command
,
2178 Tcl_CreateObjCommand (interp
, "gdb_get_file", gdb_get_file_command
,
2180 Tcl_CreateObjCommand (interp
, "gdb_tracepoint_exists",
2181 gdb_tracepoint_exists_command
, NULL
, NULL
);
2182 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_info",
2183 gdb_get_tracepoint_info
, NULL
, NULL
);
2184 Tcl_CreateObjCommand (interp
, "gdb_actions",
2185 gdb_actions_command
, NULL
, NULL
);
2186 Tcl_CreateObjCommand (interp
, "gdb_prompt",
2187 gdb_prompt_command
, NULL
, NULL
);
2188 Tcl_CreateObjCommand (interp
, "gdb_find_file",
2189 gdb_find_file_command
, NULL
, NULL
);
2190 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_list",
2191 gdb_get_tracepoint_list
, NULL
, NULL
);
2192 Tcl_CreateCommand (interp
, "gdb_pc_reg", get_pc_register
, NULL
, NULL
);
2193 Tcl_CreateObjCommand (interp
, "gdb_loadfile", gdb_loadfile
, NULL
, NULL
);
2194 Tcl_CreateObjCommand (interp
, "gdb_set_bp", gdb_set_bp
, NULL
, NULL
);
2196 command_loop_hook
= tk_command_loop
;
2197 print_frame_info_listing_hook
= gdbtk_print_frame_info
;
2198 query_hook
= gdbtk_query
;
2199 flush_hook
= gdbtk_flush
;
2200 create_breakpoint_hook
= gdbtk_create_breakpoint
;
2201 delete_breakpoint_hook
= gdbtk_delete_breakpoint
;
2202 modify_breakpoint_hook
= gdbtk_modify_breakpoint
;
2203 interactive_hook
= gdbtk_interactive
;
2204 target_wait_hook
= gdbtk_wait
;
2205 call_command_hook
= gdbtk_call_command
;
2206 readline_begin_hook
= gdbtk_readline_begin
;
2207 readline_hook
= gdbtk_readline
;
2208 readline_end_hook
= gdbtk_readline_end
;
2209 ui_load_progress_hook
= gdbtk_load_hash
;
2210 pre_add_symbol_hook
= gdbtk_pre_add_symbol
;
2211 post_add_symbol_hook
= gdbtk_post_add_symbol
;
2212 create_tracepoint_hook
= gdbtk_create_tracepoint
;
2213 delete_tracepoint_hook
= gdbtk_delete_tracepoint
;
2214 modify_tracepoint_hook
= gdbtk_modify_tracepoint
;
2215 pc_changed_hook
= pc_changed
;
2217 annotate_starting_hook
= gdbtk_annotate_starting
;
2218 annotate_stopped_hook
= gdbtk_annotate_stopped
;
2219 annotate_signalled_hook
= gdbtk_annotate_signalled
;
2220 annotate_exited_hook
= gdbtk_annotate_exited
;
2221 ui_loop_hook
= x_event
;
2224 /* Get the file descriptor for the X server */
2226 x_fd
= ConnectionNumber (Tk_Display (Tk_MainWindow (interp
)));
2228 /* Setup for I/O interrupts */
2230 action
.sa_mask
= nullsigmask
;
2231 action
.sa_flags
= 0;
2232 action
.sa_handler
= SIG_IGN
;
2233 sigaction(SIGIO
, &action
, NULL
);
2237 if (ioctl (x_fd
, FIOASYNC
, &i
))
2238 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
2242 if (ioctl (x_fd
, SIOCSPGRP
, &i
))
2243 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
2248 if (fcntl (x_fd
, F_SETOWN
, i
))
2249 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
2250 #endif /* F_SETOWN */
2251 #endif /* !SIOCSPGRP */
2254 if (ioctl (x_fd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
2255 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
2258 #endif /* ifndef FIOASYNC */
2261 add_com ("tk", class_obscure
, tk_command
,
2262 "Send a command directly into tk.");
2264 Tcl_LinkVar (interp
, "disassemble-from-exec", (char *)&disassemble_from_exec
,
2267 /* find the gdb tcl library and source main.tcl */
2269 gdbtk_lib
= getenv ("GDBTK_LIBRARY");
2271 if (access ("gdbtcl/main.tcl", R_OK
) == 0)
2272 gdbtk_lib
= "gdbtcl";
2274 gdbtk_lib
= GDBTK_LIBRARY
;
2276 gdbtk_lib_tmp
= xstrdup (gdbtk_lib
);
2279 /* see if GDBTK_LIBRARY is a path list */
2280 lib
= strtok (gdbtk_lib_tmp
, GDBTK_PATH_SEP
);
2283 if (Tcl_VarEval (interp
, "lappend auto_path ", lib
, NULL
) != TCL_OK
)
2285 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2290 gdbtk_file
= concat (lib
, "/main.tcl", (char *) NULL
);
2291 if (access (gdbtk_file
, R_OK
) == 0)
2294 Tcl_SetVar (interp
, "GDBTK_LIBRARY", lib
, 0);
2298 while ((lib
= strtok (NULL
, ":")) != NULL
);
2300 free (gdbtk_lib_tmp
);
2304 /* Try finding it with the auto path. */
2306 static const char script
[] ="\
2307 proc gdbtk_find_main {} {\n\
2308 global auto_path GDBTK_LIBRARY\n\
2309 foreach dir $auto_path {\n\
2310 set f [file join $dir main.tcl]\n\
2311 if {[file exists $f]} then {\n\
2312 set GDBTK_LIBRARY $dir\n\
2320 if (Tcl_GlobalEval (interp
, (char *) script
) != TCL_OK
)
2322 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2326 if (interp
->result
[0] != '\0')
2328 gdbtk_file
= xstrdup (interp
->result
);
2335 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2336 if (getenv("GDBTK_LIBRARY"))
2338 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
2339 fprintf_unfiltered (stderr
,
2340 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
2344 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY
);
2345 fprintf_unfiltered (stderr
, "You might want to set GDBTK_LIBRARY\n");
2350 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
2351 prior to this point go to stdout/stderr. */
2353 fputs_unfiltered_hook
= gdbtk_fputs
;
2355 if (Tcl_EvalFile (interp
, gdbtk_file
) != TCL_OK
)
2359 /* Force errorInfo to be set up propertly. */
2360 Tcl_AddErrorInfo (interp
, "");
2362 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
2364 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2367 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
2369 fputs_unfiltered (msg
, gdb_stderr
);
2376 /* start-sanitize-ide */
2377 /* Don't do this until we have initialized. Otherwise, we may get a
2378 run command before we are ready for one. */
2379 if (ide_run_server_init (interp
, h
) != TCL_OK
)
2380 error ("ide_run_server_init failed: %s", interp
->result
);
2381 /* end-sanitize-ide */
2386 discard_cleanups (old_chain
);
2390 gdb_target_has_execution_command (clientData
, interp
, argc
, argv
)
2391 ClientData clientData
;
2398 if (target_has_execution
&& inferior_pid
!= 0)
2401 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2406 gdb_trace_status (clientData
, interp
, argc
, argv
)
2407 ClientData clientData
;
2414 if (trace_running_p
)
2417 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2421 /* gdb_load_info - returns information about the file about to be downloaded */
2424 gdb_load_info (clientData
, interp
, objc
, objv
)
2425 ClientData clientData
;
2428 Tcl_Obj
*CONST objv
[];
2431 struct cleanup
*old_cleanups
;
2437 char *filename
= Tcl_GetStringFromObj (objv
[1], NULL
);
2439 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
2440 if (loadfile_bfd
== NULL
)
2442 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Open failed", -1));
2445 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
2447 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2449 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Bad Object File", -1));
2453 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
2455 if (s
->flags
& SEC_LOAD
)
2457 bfd_size_type size
= bfd_get_section_size_before_reloc (s
);
2460 ob
[0] = Tcl_NewStringObj((char *)bfd_get_section_name(loadfile_bfd
, s
), -1);
2461 ob
[1] = Tcl_NewLongObj ((long)size
);
2462 res
[i
++] = Tcl_NewListObj (2, ob
);
2467 Tcl_SetObjResult (interp
, Tcl_NewListObj (i
, res
));
2468 do_cleanups (old_cleanups
);
2474 gdbtk_load_hash (section
, num
)
2479 sprintf (buf
, "download_hash %s %ld", section
, num
);
2480 Tcl_Eval (interp
, buf
);
2481 return atoi (interp
->result
);
2484 /* gdb_get_vars_command -
2486 * Implements the "gdb_get_locals" and "gdb_get_args" tcl commands. This
2487 * function sets the Tcl interpreter's result to a list of variable names
2488 * depending on clientData. If clientData is one, the result is a list of
2489 * arguments; zero returns a list of locals -- all relative to the block
2490 * specified as an argument to the command. Valid commands include
2491 * anything decode_line_1 can handle (like "main.c:2", "*0x02020202",
2495 gdb_get_vars_command (clientData
, interp
, objc
, objv
)
2496 ClientData clientData
;
2499 Tcl_Obj
*CONST objv
[];
2502 struct symtabs_and_lines sals
;
2504 struct block
*block
;
2505 char **canonical
, *args
;
2506 int i
, nsyms
, arguments
;
2510 Tcl_AppendResult (interp
,
2511 "wrong # of args: should be \"",
2512 Tcl_GetStringFromObj (objv
[0], NULL
),
2513 " function:line|function|line|*addr\"");
2517 arguments
= (int) clientData
;
2518 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2519 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2520 if (sals
.nelts
== 0)
2522 Tcl_AppendResult (interp
,
2523 "error decoding line", NULL
);
2527 /* Initialize a list that will hold the results */
2528 result
= Tcl_NewListObj (0, NULL
);
2530 /* Resolve all line numbers to PC's */
2531 for (i
= 0; i
< sals
.nelts
; i
++)
2532 resolve_sal_pc (&sals
.sals
[i
]);
2534 block
= block_for_pc (sals
.sals
[0].pc
);
2537 nsyms
= BLOCK_NSYMS (block
);
2538 for (i
= 0; i
< nsyms
; i
++)
2540 sym
= BLOCK_SYM (block
, i
);
2541 switch (SYMBOL_CLASS (sym
)) {
2543 case LOC_UNDEF
: /* catches errors */
2544 case LOC_CONST
: /* constant */
2545 case LOC_STATIC
: /* static */
2546 case LOC_REGISTER
: /* register */
2547 case LOC_TYPEDEF
: /* local typedef */
2548 case LOC_LABEL
: /* local label */
2549 case LOC_BLOCK
: /* local function */
2550 case LOC_CONST_BYTES
: /* loc. byte seq. */
2551 case LOC_UNRESOLVED
: /* unresolved static */
2552 case LOC_OPTIMIZED_OUT
: /* optimized out */
2554 case LOC_ARG
: /* argument */
2555 case LOC_REF_ARG
: /* reference arg */
2556 case LOC_REGPARM
: /* register arg */
2557 case LOC_REGPARM_ADDR
: /* indirect register arg */
2558 case LOC_LOCAL_ARG
: /* stack arg */
2559 case LOC_BASEREG_ARG
: /* basereg arg */
2561 Tcl_ListObjAppendElement (interp
, result
,
2562 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2564 case LOC_LOCAL
: /* stack local */
2565 case LOC_BASEREG
: /* basereg local */
2567 Tcl_ListObjAppendElement (interp
, result
,
2568 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2572 if (BLOCK_FUNCTION (block
))
2575 block
= BLOCK_SUPERBLOCK (block
);
2578 Tcl_SetObjResult (interp
, result
);
2583 gdb_get_line_command (clientData
, interp
, objc
, objv
)
2584 ClientData clientData
;
2587 Tcl_Obj
*CONST objv
[];
2590 struct symtabs_and_lines sals
;
2591 char *args
, **canonical
;
2595 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2596 Tcl_GetStringFromObj (objv
[0], NULL
),
2601 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2602 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2603 if (sals
.nelts
== 1)
2605 Tcl_SetObjResult (interp
, Tcl_NewIntObj (sals
.sals
[0].line
));
2609 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2614 gdb_get_file_command (clientData
, interp
, objc
, objv
)
2615 ClientData clientData
;
2618 Tcl_Obj
*CONST objv
[];
2621 struct symtabs_and_lines sals
;
2622 char *args
, **canonical
;
2626 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2627 Tcl_GetStringFromObj (objv
[0], NULL
),
2632 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2633 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2634 if (sals
.nelts
== 1)
2636 Tcl_SetResult (interp
, sals
.sals
[0].symtab
->filename
, TCL_VOLATILE
);
2640 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2645 gdb_get_function_command (clientData
, interp
, objc
, objv
)
2646 ClientData clientData
;
2649 Tcl_Obj
*CONST objv
[];
2653 struct symtabs_and_lines sals
;
2654 char *args
, **canonical
;
2658 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2659 Tcl_GetStringFromObj (objv
[0], NULL
),
2664 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2665 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2666 if (sals
.nelts
== 1)
2668 resolve_sal_pc (&sals
.sals
[0]);
2669 find_pc_partial_function (sals
.sals
[0].pc
, &function
, NULL
, NULL
);
2670 if (function
!= NULL
)
2672 Tcl_SetResult (interp
, function
, TCL_VOLATILE
);
2677 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2682 gdb_get_tracepoint_info (clientData
, interp
, objc
, objv
)
2683 ClientData clientData
;
2686 Tcl_Obj
*CONST objv
[];
2688 struct symtab_and_line sal
;
2690 struct tracepoint
*tp
;
2691 struct action_line
*al
;
2692 Tcl_Obj
*list
, *action_list
;
2693 char *filename
, *funcname
;
2697 error ("wrong # args");
2699 Tcl_GetIntFromObj (NULL
, objv
[1], &tpnum
);
2701 ALL_TRACEPOINTS (tp
)
2702 if (tp
->number
== tpnum
)
2706 error ("Tracepoint #%d does not exist", tpnum
);
2708 list
= Tcl_NewListObj (0, NULL
);
2709 sal
= find_pc_line (tp
->address
, 0);
2710 filename
= symtab_to_filename (sal
.symtab
);
2711 if (filename
== NULL
)
2713 Tcl_ListObjAppendElement (interp
, list
,
2714 Tcl_NewStringObj (filename
, -1));
2715 find_pc_partial_function (tp
->address
, &funcname
, NULL
, NULL
);
2716 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (funcname
, -1));
2717 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (sal
.line
));
2718 sprintf (tmp
, "0x%lx", tp
->address
);
2719 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tmp
, -1));
2720 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->enabled
));
2721 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->pass_count
));
2722 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->step_count
));
2723 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->thread
));
2724 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->hit_count
));
2726 /* Append a list of actions */
2727 action_list
= Tcl_NewListObj (0, NULL
);
2728 for (al
= tp
->actions
; al
!= NULL
; al
= al
->next
)
2730 Tcl_ListObjAppendElement (interp
, action_list
,
2731 Tcl_NewStringObj (al
->action
, -1));
2733 Tcl_ListObjAppendElement (interp
, list
, action_list
);
2735 Tcl_SetObjResult (interp
, list
);
2740 /* TclDebug (const char *fmt, ...) works just like printf() but */
2741 /* sends the output to the GDB TK debug window. */
2742 /* Not for normal use; just a convenient tool for debugging */
2744 #ifdef ANSI_PROTOTYPES
2745 TclDebug (const char *fmt
, ...)
2752 char buf
[512], *v
[2], *merge
;
2754 #ifdef ANSI_PROTOTYPES
2755 va_start (args
, fmt
);
2759 fmt
= va_arg (args
, char *);
2765 vsprintf (buf
, fmt
, args
);
2768 merge
= Tcl_Merge (2, v
);
2769 Tcl_Eval (interp
, merge
);
2774 /* Find the full pathname to a file, searching the symbol tables */
2777 gdb_find_file_command (clientData
, interp
, objc
, objv
)
2778 ClientData clientData
;
2781 Tcl_Obj
*CONST objv
[];
2783 char *filename
= NULL
;
2788 Tcl_WrongNumArgs(interp
, 1, objv
, "filename");
2792 st
= full_lookup_symtab (Tcl_GetStringFromObj (objv
[1], NULL
));
2794 filename
= st
->fullname
;
2796 if (filename
== NULL
)
2797 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("", 0));
2799 Tcl_SetObjResult (interp
, Tcl_NewStringObj (filename
, -1));
2805 gdbtk_create_tracepoint (tp
)
2806 struct tracepoint
*tp
;
2808 tracepoint_notify (tp
, "create");
2812 gdbtk_delete_tracepoint (tp
)
2813 struct tracepoint
*tp
;
2815 tracepoint_notify (tp
, "delete");
2819 gdbtk_modify_tracepoint (tp
)
2820 struct tracepoint
*tp
;
2822 tracepoint_notify (tp
, "modify");
2826 tracepoint_notify(tp
, action
)
2827 struct tracepoint
*tp
;
2832 struct symtab_and_line sal
;
2835 /* We ensure that ACTION contains no special Tcl characters, so we
2837 sal
= find_pc_line (tp
->address
, 0);
2839 filename
= symtab_to_filename (sal
.symtab
);
2840 if (filename
== NULL
)
2842 sprintf (buf
, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s}", action
, tp
->number
,
2843 (long)tp
->address
, sal
.line
, filename
, tp
->pass_count
);
2845 v
= Tcl_Eval (interp
, buf
);
2849 gdbtk_fputs (interp
->result
, gdb_stdout
);
2850 gdbtk_fputs ("\n", gdb_stdout
);
2854 /* returns -1 if not found, tracepoint # if found */
2856 tracepoint_exists (char * args
)
2858 struct tracepoint
*tp
;
2860 struct symtabs_and_lines sals
;
2864 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2865 if (sals
.nelts
== 1)
2867 resolve_sal_pc (&sals
.sals
[0]);
2868 file
= xmalloc (strlen (sals
.sals
[0].symtab
->dirname
)
2869 + strlen (sals
.sals
[0].symtab
->filename
) + 1);
2872 strcpy (file
, sals
.sals
[0].symtab
->dirname
);
2873 strcat (file
, sals
.sals
[0].symtab
->filename
);
2875 ALL_TRACEPOINTS (tp
)
2877 if (tp
->address
== sals
.sals
[0].pc
)
2878 result
= tp
->number
;
2880 /* Why is this here? This messes up assembly traces */
2881 else if (tp
->source_file
!= NULL
2882 && strcmp (tp
->source_file
, file
) == 0
2883 && sals
.sals
[0].line
== tp
->line_number
)
2884 result
= tp
->number
;
2895 gdb_actions_command (clientData
, interp
, objc
, objv
)
2896 ClientData clientData
;
2899 Tcl_Obj
*CONST objv
[];
2901 struct tracepoint
*tp
;
2903 int nactions
, i
, len
;
2904 char *number
, *args
, *action
;
2906 struct action_line
*next
= NULL
, *temp
;
2910 Tcl_AppendResult (interp
, "wrong # args: should be: \"",
2911 Tcl_GetStringFromObj (objv
[0], NULL
),
2912 " number actions\"");
2916 args
= number
= Tcl_GetStringFromObj (objv
[1], NULL
);
2917 tp
= get_tracepoint_by_number (&args
);
2920 Tcl_AppendResult (interp
, "Tracepoint \"", number
, "\" does not exist");
2924 /* Free any existing actions */
2925 if (tp
->actions
!= NULL
)
2930 Tcl_ListObjGetElements (interp
, objv
[2], &nactions
, &actions
);
2931 for (i
= 0; i
< nactions
; i
++)
2933 temp
= xmalloc (sizeof (struct action_line
));
2935 action
= Tcl_GetStringFromObj (actions
[i
], &len
);
2936 temp
->action
= savestring (action
, len
);
2937 if (sscanf (temp
->action
, "while-stepping %d", &step_count
) !=0)
2938 tp
->step_count
= step_count
;
2955 gdb_tracepoint_exists_command (clientData
, interp
, objc
, objv
)
2956 ClientData clientData
;
2959 Tcl_Obj
*CONST objv
[];
2965 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2966 Tcl_GetStringFromObj (objv
[0], NULL
),
2967 " function:line|function|line|*addr\"");
2971 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2973 Tcl_SetObjResult (interp
, Tcl_NewIntObj (tracepoint_exists (args
)));
2977 /* Return the prompt to the interpreter */
2979 gdb_prompt_command (clientData
, interp
, objc
, objv
)
2980 ClientData clientData
;
2983 Tcl_Obj
*CONST objv
[];
2985 Tcl_SetResult (interp
, get_prompt (), TCL_VOLATILE
);
2989 /* return a list of all tracepoint numbers in interpreter */
2991 gdb_get_tracepoint_list (clientData
, interp
, objc
, objv
)
2992 ClientData clientData
;
2995 Tcl_Obj
*CONST objv
[];
2998 struct tracepoint
*tp
;
3000 list
= Tcl_NewListObj (0, NULL
);
3002 ALL_TRACEPOINTS (tp
)
3003 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->number
));
3005 Tcl_SetObjResult (interp
, list
);
3010 /* This hook is called whenever we are ready to load a symbol file so that
3011 the UI can notify the user... */
3013 gdbtk_pre_add_symbol (name
)
3018 v
[0] = "gdbtk_tcl_pre_add_symbol";
3020 merge
= Tcl_Merge (2, v
);
3021 Tcl_Eval (interp
, merge
);
3025 /* This hook is called whenever we finish loading a symbol file. */
3027 gdbtk_post_add_symbol ()
3029 Tcl_Eval (interp
, "gdbtk_tcl_post_add_symbol");
3035 gdbtk_print_frame_info (s
, line
, stopline
, noerror
)
3041 current_source_symtab
= s
;
3042 current_source_line
= line
;
3046 /* The lookup_symtab() in symtab.c doesn't work correctly */
3047 /* It will not work will full pathnames and if multiple */
3048 /* source files have the same basename, it will return */
3049 /* the first one instead of the correct one. This version */
3050 /* also always makes sure symtab->fullname is set. */
3052 static struct symtab
*
3053 full_lookup_symtab(file
)
3057 struct objfile
*objfile
;
3058 char *bfile
, *fullname
;
3059 struct partial_symtab
*pt
;
3064 /* first try a direct lookup */
3065 st
= lookup_symtab (file
);
3069 symtab_to_filename(st
);
3073 /* if the direct approach failed, try */
3074 /* looking up the basename and checking */
3075 /* all matches with the fullname */
3076 bfile
= basename (file
);
3077 ALL_SYMTABS (objfile
, st
)
3079 if (!strcmp (bfile
, basename(st
->filename
)))
3082 fullname
= symtab_to_filename (st
);
3084 fullname
= st
->fullname
;
3086 if (!strcmp (file
, fullname
))
3091 /* still no luck? look at psymtabs */
3092 ALL_PSYMTABS (objfile
, pt
)
3094 if (!strcmp (bfile
, basename(pt
->filename
)))
3096 st
= PSYMTAB_TO_SYMTAB (pt
);
3099 fullname
= symtab_to_filename (st
);
3100 if (!strcmp (file
, fullname
))
3109 /* gdb_loadfile loads a c source file into a text widget. */
3111 /* LTABLE_SIZE is the number of bytes to allocate for the */
3112 /* line table. Its size limits the maximum number of lines */
3113 /* in a file to 8 * LTABLE_SIZE. This memory is freed after */
3114 /* the file is loaded, so it is OK to make this very large. */
3115 /* Additional memory will be allocated if needed. */
3116 #define LTABLE_SIZE 20000
3119 gdb_loadfile (clientData
, interp
, objc
, objv
)
3120 ClientData clientData
;
3123 Tcl_Obj
*CONST objv
[];
3125 char *file
, *widget
, *line
, *buf
, msg
[128];
3126 int linenumbers
, ln
, anum
, lnum
, ltable_size
;
3127 Tcl_Obj
*a
[2], *b
[2], *cmd
;
3130 struct symtab
*symtab
;
3131 struct linetable_entry
*le
;
3135 Tcl_WrongNumArgs(interp
, 1, objv
, "widget filename linenumbers");
3139 widget
= Tcl_GetStringFromObj (objv
[1], NULL
);
3140 file
= Tcl_GetStringFromObj (objv
[2], NULL
);
3141 Tcl_GetBooleanFromObj (interp
, objv
[3], &linenumbers
);
3143 if ((fp
= fopen ( file
, "r" )) == NULL
)
3146 symtab
= full_lookup_symtab (file
);
3149 sprintf(msg
, "File not found");
3150 Tcl_SetStringObj ( Tcl_GetObjResult (interp
), msg
, -1);
3155 /* Source linenumbers don't appear to be in order, and a sort is */
3156 /* too slow so the fastest solution is just to allocate a huge */
3157 /* array and set the array entry for each linenumber */
3159 ltable_size
= LTABLE_SIZE
;
3160 ltable
= (char *)malloc (LTABLE_SIZE
);
3163 sprintf(msg
, "Out of memory.");
3164 Tcl_SetStringObj ( Tcl_GetObjResult (interp
), msg
, -1);
3169 memset (ltable
, 0, LTABLE_SIZE
);
3171 if (symtab
->linetable
&& symtab
->linetable
->nitems
)
3173 le
= symtab
->linetable
->item
;
3174 for (ln
= symtab
->linetable
->nitems
;ln
> 0; ln
--, le
++)
3176 lnum
= le
->line
>> 3;
3177 if (lnum
>= ltable_size
)
3180 new_ltable
= (char *)realloc (ltable
, ltable_size
*2);
3181 memset (new_ltable
+ ltable_size
, 0, ltable_size
);
3183 if (new_ltable
== NULL
)
3185 sprintf(msg
, "Out of memory.");
3186 Tcl_SetStringObj ( Tcl_GetObjResult (interp
), msg
, -1);
3191 ltable
= new_ltable
;
3193 ltable
[lnum
] |= 1 << (le
->line
% 8);
3197 /* create an object with enough space, then grab its */
3198 /* buffer and sprintf directly into it. */
3199 a
[0] = Tcl_NewStringObj (ltable
, 1024);
3200 a
[1] = Tcl_NewListObj(0,NULL
);
3202 b
[0] = Tcl_NewStringObj (ltable
,1024);
3203 b
[1] = Tcl_NewStringObj ("source_tag", -1);
3204 Tcl_IncrRefCount (b
[0]);
3205 Tcl_IncrRefCount (b
[1]);
3206 line
= b
[0]->bytes
+ 1;
3207 strcpy(b
[0]->bytes
,"\t");
3210 while (fgets (line
, 980, fp
))
3214 if (ltable
[ln
>> 3] & (1 << (ln
% 8)))
3216 sprintf (buf
,"%s insert end {-\t%d} break_tag", widget
, ln
);
3217 a
[0]->length
= strlen (buf
);
3221 sprintf (buf
,"%s insert end { \t%d} \"\"", widget
, ln
);
3222 a
[0]->length
= strlen (buf
);
3227 if (ltable
[ln
>> 3] & (1 << (ln
% 8)))
3229 sprintf (buf
,"%s insert end {-\t} break_tag", widget
);
3230 a
[0]->length
= strlen (buf
);
3234 sprintf (buf
,"%s insert end { \t} \"\"", widget
);
3235 a
[0]->length
= strlen (buf
);
3238 b
[0]->length
= strlen(b
[0]->bytes
);
3239 Tcl_SetListObj(a
[1],2,b
);
3240 cmd
= Tcl_ConcatObj(2,a
);
3241 Tcl_EvalObj (interp
, cmd
);
3242 Tcl_DecrRefCount (cmd
);
3245 Tcl_DecrRefCount (b
[0]);
3246 Tcl_DecrRefCount (b
[0]);
3247 Tcl_DecrRefCount (b
[1]);
3248 Tcl_DecrRefCount (b
[1]);
3254 /* at some point make these static in breakpoint.c and move GUI code there */
3255 extern struct breakpoint
*set_raw_breakpoint (struct symtab_and_line sal
);
3256 extern void set_breakpoint_count (int);
3257 extern int breakpoint_count
;
3259 /* set a breakpoint by source file and line number */
3260 /* flags are as follows: */
3261 /* least significant 2 bits are disposition, rest is */
3262 /* type (normally 0).
3265 bp_breakpoint, Normal breakpoint
3266 bp_hardware_breakpoint, Hardware assisted breakpoint
3269 Disposition of breakpoint. Ie: what to do after hitting it.
3272 del_at_next_stop, Delete at next stop, whether hit or not
3274 donttouch Leave it alone
3279 gdb_set_bp (clientData
, interp
, objc
, objv
)
3280 ClientData clientData
;
3283 Tcl_Obj
*CONST objv
[];
3286 struct symtab_and_line sal
;
3287 int line
, flags
, ret
;
3288 struct breakpoint
*b
;
3290 Tcl_Obj
*a
[5], *cmd
;
3294 Tcl_WrongNumArgs(interp
, 1, objv
, "filename line type");
3298 sal
.symtab
= full_lookup_symtab (Tcl_GetStringFromObj( objv
[1], NULL
));
3299 if (sal
.symtab
== NULL
)
3302 if (Tcl_GetIntFromObj( interp
, objv
[2], &line
) == TCL_ERROR
)
3305 if (Tcl_GetIntFromObj( interp
, objv
[3], &flags
) == TCL_ERROR
)
3309 sal
.pc
= find_line_pc (sal
.symtab
, sal
.line
);
3313 sal
.section
= find_pc_overlay (sal
.pc
);
3314 b
= set_raw_breakpoint (sal
);
3315 set_breakpoint_count (breakpoint_count
+ 1);
3316 b
->number
= breakpoint_count
;
3317 b
->type
= flags
>> 2;
3318 b
->disposition
= flags
& 3;
3320 /* FIXME: this won't work for duplicate basenames! */
3321 sprintf (buf
, "%s:%d", basename(Tcl_GetStringFromObj( objv
[1], NULL
)), line
);
3322 b
->addr_string
= strsave (buf
);
3324 /* now send notification command back to GUI */
3325 sprintf (buf
, "0x%x", sal
.pc
);
3326 a
[0] = Tcl_NewStringObj ("gdbtk_tcl_breakpoint create", -1);
3327 a
[1] = Tcl_NewIntObj (b
->number
);
3328 a
[2] = Tcl_NewStringObj (buf
, -1);
3330 a
[4] = Tcl_NewListObj (1,&objv
[1]);
3331 cmd
= Tcl_ConcatObj(5,a
);
3332 ret
= Tcl_EvalObj (interp
, cmd
);
3333 Tcl_DecrRefCount (cmd
);
3338 /* The whole timer idea is an easy one, but POSIX does not appear to have
3339 some sort of interval timer requirement. Consequently, we cannot rely
3340 on cygwin32 to always deliver the timer's signal. This is especially
3341 painful given that all serial I/O will block the timer right now. */
3343 gdbtk_annotate_starting ()
3345 /* TclDebug ("### STARTING ###"); */
3346 gdbtk_start_timer ();
3350 gdbtk_annotate_stopped ()
3352 /* TclDebug ("### STOPPED ###"); */
3353 gdbtk_stop_timer ();
3357 gdbtk_annotate_exited ()
3359 /* TclDebug ("### EXITED ###"); */
3360 gdbtk_stop_timer ();
3364 gdbtk_annotate_signalled ()
3366 /* TclDebug ("### SIGNALLED ###"); */
3367 gdbtk_stop_timer ();
3371 /* Come here during initialize_all_files () */
3374 _initialize_gdbtk ()
3378 /* Tell the rest of the world that Gdbtk is now set up. */
3380 init_ui_hook
= gdbtk_init
;