1 /* Tcl/Tk interface routines.
2 Copyright 1994, 1995, 1996, 1997 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"
44 /* start-sanitize-ide */
48 /* end-sanitize-ide */
51 #ifdef ANSI_PROTOTYPES
61 #include <sys/ioctl.h>
62 #include "gdb_string.h"
69 #include <sys/stropts.h>
78 #define GDBTK_PATH_SEP ";"
80 #define GDBTK_PATH_SEP ":"
83 /* Some versions (1.3.79, 1.3.81) of Linux don't support SIOCSPGRP the way
84 gdbtk wants to use it... */
89 int gdbtk_load_hash
PARAMS ((char *, unsigned long));
90 int (*ui_load_progress_hook
) PARAMS ((char *, unsigned long));
92 static void null_routine
PARAMS ((int));
93 static void gdbtk_flush
PARAMS ((FILE *));
94 static void gdbtk_fputs
PARAMS ((const char *, FILE *));
95 static int gdbtk_query
PARAMS ((const char *, va_list));
96 static char *gdbtk_readline
PARAMS ((char *));
97 static void gdbtk_init
PARAMS ((char *));
98 static void tk_command_loop
PARAMS ((void));
99 static void gdbtk_call_command
PARAMS ((struct cmd_list_element
*, char *, int));
100 static int gdbtk_wait
PARAMS ((int, struct target_waitstatus
*));
101 static void x_event
PARAMS ((int));
102 static void gdbtk_interactive
PARAMS ((void));
103 static void cleanup_init
PARAMS ((int));
104 static void tk_command
PARAMS ((char *, int));
105 static int gdb_disassemble
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
106 static int compare_lines
PARAMS ((const PTR
, const PTR
));
107 static int gdbtk_dis_asm_read_memory
PARAMS ((bfd_vma
, bfd_byte
*, int, disassemble_info
*));
108 static int gdb_path_conv
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
109 static int gdb_stop
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
110 static int gdb_confirm_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
111 static int gdb_force_quit
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
112 static int gdb_listfiles
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
113 static int gdb_listfuncs
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
114 static int call_wrapper
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
115 static int gdb_cmd
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
116 static int gdb_fetch_registers
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
117 static void gdbtk_readline_end
PARAMS ((void));
118 static int gdb_changed_register_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
119 static void register_changed_p
PARAMS ((int, void *));
120 static int gdb_get_breakpoint_list
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
121 static int gdb_get_breakpoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
122 static void breakpoint_notify
PARAMS ((struct breakpoint
*, const char *));
123 static void gdbtk_create_breakpoint
PARAMS ((struct breakpoint
*));
124 static void gdbtk_delete_breakpoint
PARAMS ((struct breakpoint
*));
125 static void gdbtk_modify_breakpoint
PARAMS ((struct breakpoint
*));
126 static int gdb_loc
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
127 static int gdb_eval
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
128 static int gdb_sourcelines
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
129 static int map_arg_registers
PARAMS ((int, char *[], void (*) (int, void *), void *));
130 static void get_register_name
PARAMS ((int, void *));
131 static int gdb_regnames
PARAMS ((ClientData
, Tcl_Interp
*, int, char *[]));
132 static void get_register
PARAMS ((int, void *));
133 static int gdb_target_has_execution_command
PARAMS ((ClientData
, Tcl_Interp
*, int, char *argv
[]));
134 static int gdb_load_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
135 static int gdb_get_vars_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
136 static int gdb_get_function_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
137 static int gdb_get_line_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
138 static int gdb_get_file_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
139 static int gdb_tracepoint_exists_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
140 static int gdb_get_tracepoint_info
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
141 static int gdb_actions_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
142 static int gdb_prompt_command
PARAMS ((ClientData
, Tcl_Interp
*, int, Tcl_Obj
*CONST objv
[]));
143 static void gdbtk_create_tracepoint
PARAMS ((struct tracepoint
*));
144 static void gdbtk_delete_tracepoint
PARAMS ((struct tracepoint
*));
145 static void tracepoint_notify
PARAMS ((struct tracepoint
*, const char *));
147 /* Handle for TCL interpreter */
149 static Tcl_Interp
*interp
= NULL
;
152 static int x_fd
; /* X network socket */
155 /* This variable is true when the inferior is running. Although it's
156 possible to disable most input from widgets and thus prevent
157 attempts to do anything while the inferior is running, any commands
158 that get through - even a simple memory read - are Very Bad, and
159 may cause GDB to crash or behave strangely. So, this variable
160 provides an extra layer of defense. */
162 static int running_now
;
164 /* This variable determines where memory used for disassembly is read from.
165 If > 0, then disassembly comes from the exec file rather than the
166 target (which might be at the other end of a slow serial link). If
167 == 0 then disassembly comes from target. If < 0 disassembly is
168 automatically switched to the target if it's an inferior process,
169 otherwise the exec file is used. */
171 static int disassemble_from_exec
= -1;
175 /* Supply malloc calls for tcl/tk. We do not want to do this on
176 Windows, because Tcl_Alloc is probably in a DLL which will not call
177 the mmalloc routines. */
183 return xmalloc (size
);
187 Tcl_Realloc (ptr
, size
)
191 return xrealloc (ptr
, size
);
201 #endif /* ! _WIN32 */
211 /* On Windows, if we hold a file open, other programs can't write to
212 it. In particular, we don't want to hold the executable open,
213 because it will mean that people have to get out of the debugging
214 session in order to remake their program. So we close it, although
215 this will cost us if and when we need to reopen it. */
225 bfd_cache_close (o
->obfd
);
228 if (exec_bfd
!= NULL
)
229 bfd_cache_close (exec_bfd
);
234 /* The following routines deal with stdout/stderr data, which is created by
235 {f}printf_{un}filtered and friends. gdbtk_fputs and gdbtk_flush are the
236 lowest level of these routines and capture all output from the rest of GDB.
237 Normally they present their data to tcl via callbacks to the following tcl
238 routines: gdbtk_tcl_fputs, gdbtk_tcl_fputs_error, and gdbtk_flush. These
239 in turn call tk routines to update the display.
241 Under some circumstances, you may want to collect the output so that it can
242 be returned as the value of a tcl procedure. This can be done by
243 surrounding the output routines with calls to start_saving_output and
244 finish_saving_output. The saved data can then be retrieved with
245 get_saved_output (but this must be done before the call to
246 finish_saving_output). */
248 /* Dynamic string for output. */
250 static Tcl_DString
*result_ptr
;
252 /* Dynamic string for stderr. This is only used if result_ptr is
255 static Tcl_DString
*error_string_ptr
;
262 /* Force immediate screen update */
264 Tcl_VarEval (interp
, "gdbtk_tcl_flush", NULL
);
269 gdbtk_fputs (ptr
, stream
)
274 Tcl_DStringAppend (result_ptr
, (char *) ptr
, -1);
275 else if (error_string_ptr
!= NULL
&& stream
== gdb_stderr
)
276 Tcl_DStringAppend (error_string_ptr
, (char *) ptr
, -1);
281 Tcl_DStringInit (&str
);
283 Tcl_DStringAppend (&str
, "gdbtk_tcl_fputs", -1);
284 Tcl_DStringAppendElement (&str
, (char *)ptr
);
286 Tcl_Eval (interp
, Tcl_DStringValue (&str
));
287 Tcl_DStringFree (&str
);
292 gdbtk_query (query
, args
)
296 char buf
[200], *merge
[2];
300 vsprintf (buf
, query
, args
);
301 merge
[0] = "gdbtk_tcl_query";
303 command
= Tcl_Merge (2, merge
);
304 Tcl_Eval (interp
, command
);
307 val
= atol (interp
->result
);
313 #ifdef ANSI_PROTOTYPES
314 gdbtk_readline_begin (char *format
, ...)
316 gdbtk_readline_begin (va_alist
)
321 char buf
[200], *merge
[2];
324 #ifdef ANSI_PROTOTYPES
325 va_start (args
, format
);
329 format
= va_arg (args
, char *);
332 vsprintf (buf
, format
, args
);
333 merge
[0] = "gdbtk_tcl_readline_begin";
335 command
= Tcl_Merge (2, merge
);
336 Tcl_Eval (interp
, command
);
341 gdbtk_readline (prompt
)
352 merge
[0] = "gdbtk_tcl_readline";
354 command
= Tcl_Merge (2, merge
);
355 result
= Tcl_Eval (interp
, command
);
357 if (result
== TCL_OK
)
359 return (strdup (interp
-> result
));
363 gdbtk_fputs (interp
-> result
, gdb_stdout
);
364 gdbtk_fputs ("\n", gdb_stdout
);
370 gdbtk_readline_end ()
372 Tcl_Eval (interp
, "gdbtk_tcl_readline_end");
377 #ifdef ANSI_PROTOTYPES
378 dsprintf_append_element (Tcl_DString
*dsp
, char *format
, ...)
380 dsprintf_append_element (va_alist
)
387 #ifdef ANSI_PROTOTYPES
388 va_start (args
, format
);
394 dsp
= va_arg (args
, Tcl_DString
*);
395 format
= va_arg (args
, char *);
398 vsprintf (buf
, format
, args
);
400 Tcl_DStringAppendElement (dsp
, buf
);
404 gdb_path_conv (clientData
, interp
, argc
, argv
)
405 ClientData clientData
;
411 char pathname
[256], *ptr
;
413 error ("wrong # args");
414 cygwin32_conv_to_full_win32_path (argv
[1], pathname
);
415 for (ptr
= pathname
; *ptr
; ptr
++)
421 char *pathname
= argv
[1];
423 Tcl_DStringAppend (result_ptr
, pathname
, strlen(pathname
));
428 gdb_get_breakpoint_list (clientData
, interp
, argc
, argv
)
429 ClientData clientData
;
434 struct breakpoint
*b
;
435 extern struct breakpoint
*breakpoint_chain
;
438 error ("wrong # args");
440 for (b
= breakpoint_chain
; b
; b
= b
->next
)
441 if (b
->type
== bp_breakpoint
)
442 dsprintf_append_element (result_ptr
, "%d", b
->number
);
448 gdb_get_breakpoint_info (clientData
, interp
, argc
, argv
)
449 ClientData clientData
;
454 struct symtab_and_line sal
;
455 static char *bptypes
[] = {"breakpoint", "hardware breakpoint", "until",
456 "finish", "watchpoint", "hardware watchpoint",
457 "read watchpoint", "access watchpoint",
458 "longjmp", "longjmp resume", "step resume",
459 "through sigtramp", "watchpoint scope",
461 static char *bpdisp
[] = {"delete", "delstop", "disable", "donttouch"};
462 struct command_line
*cmd
;
464 struct breakpoint
*b
;
465 extern struct breakpoint
*breakpoint_chain
;
466 char *funcname
, *filename
;
469 error ("wrong # args");
471 bpnum
= atoi (argv
[1]);
473 for (b
= breakpoint_chain
; b
; b
= b
->next
)
474 if (b
->number
== bpnum
)
477 if (!b
|| b
->type
!= bp_breakpoint
)
478 error ("Breakpoint #%d does not exist", bpnum
);
480 sal
= find_pc_line (b
->address
, 0);
482 filename
= symtab_to_filename (sal
.symtab
);
483 if (filename
== NULL
)
485 Tcl_DStringAppendElement (result_ptr
, filename
);
486 find_pc_partial_function (b
->address
, &funcname
, NULL
, NULL
);
487 Tcl_DStringAppendElement (result_ptr
, funcname
);
488 dsprintf_append_element (result_ptr
, "%d", sal
.line
);
489 dsprintf_append_element (result_ptr
, "0x%lx", b
->address
);
490 Tcl_DStringAppendElement (result_ptr
, bptypes
[b
->type
]);
491 Tcl_DStringAppendElement (result_ptr
, b
->enable
== enabled
? "1" : "0");
492 Tcl_DStringAppendElement (result_ptr
, bpdisp
[b
->disposition
]);
493 dsprintf_append_element (result_ptr
, "%d", b
->ignore_count
);
495 Tcl_DStringStartSublist (result_ptr
);
496 for (cmd
= b
->commands
; cmd
; cmd
= cmd
->next
)
497 Tcl_DStringAppendElement (result_ptr
, cmd
->line
);
498 Tcl_DStringEndSublist (result_ptr
);
500 Tcl_DStringAppendElement (result_ptr
, b
->cond_string
);
502 dsprintf_append_element (result_ptr
, "%d", b
->thread
);
503 dsprintf_append_element (result_ptr
, "%d", b
->hit_count
);
509 breakpoint_notify(b
, action
)
510 struct breakpoint
*b
;
515 struct symtab_and_line sal
;
518 if (b
->type
!= bp_breakpoint
)
521 /* We ensure that ACTION contains no special Tcl characters, so we
523 sal
= find_pc_line (b
->address
, 0);
524 filename
= symtab_to_filename (sal
.symtab
);
525 if (filename
== NULL
)
527 sprintf (buf
, "gdbtk_tcl_breakpoint %s %d 0x%lx %d {%s}", action
, b
->number
,
528 (long)b
->address
, sal
.line
, filename
);
530 v
= Tcl_Eval (interp
, buf
);
534 gdbtk_fputs (interp
->result
, gdb_stdout
);
535 gdbtk_fputs ("\n", gdb_stdout
);
540 gdbtk_create_breakpoint(b
)
541 struct breakpoint
*b
;
543 breakpoint_notify (b
, "create");
547 gdbtk_delete_breakpoint(b
)
548 struct breakpoint
*b
;
550 breakpoint_notify (b
, "delete");
554 gdbtk_modify_breakpoint(b
)
555 struct breakpoint
*b
;
557 breakpoint_notify (b
, "modify");
560 /* This implements the TCL command `gdb_loc', which returns a list consisting
561 of the source and line number associated with the current pc. */
564 gdb_loc (clientData
, interp
, argc
, argv
)
565 ClientData clientData
;
571 struct symtab_and_line sal
;
575 if (!have_full_symbols () && !have_partial_symbols ())
577 Tcl_SetResult (interp
, "No symbol table is loaded", TCL_STATIC
);
583 pc
= selected_frame
? selected_frame
->pc
: stop_pc
;
584 sal
= find_pc_line (pc
, 0);
588 struct symtabs_and_lines sals
;
591 sals
= decode_line_spec (argv
[1], 1);
598 error ("Ambiguous line spec");
603 error ("wrong # args");
606 Tcl_DStringAppendElement (result_ptr
, sal
.symtab
->filename
);
608 Tcl_DStringAppendElement (result_ptr
, "");
610 find_pc_partial_function (pc
, &funcname
, NULL
, NULL
);
611 Tcl_DStringAppendElement (result_ptr
, funcname
);
613 filename
= symtab_to_filename (sal
.symtab
);
614 if (filename
== NULL
)
616 Tcl_DStringAppendElement (result_ptr
, filename
);
618 dsprintf_append_element (result_ptr
, "%d", sal
.line
); /* line number */
620 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(pc
)); /* PC in current frame */
622 dsprintf_append_element (result_ptr
, "0x%s", paddr_nz(stop_pc
)); /* Real PC */
627 /* This implements the TCL command `gdb_eval'. */
630 gdb_eval (clientData
, interp
, argc
, argv
)
631 ClientData clientData
;
636 struct expression
*expr
;
637 struct cleanup
*old_chain
;
641 error ("wrong # args");
643 expr
= parse_expression (argv
[1]);
645 old_chain
= make_cleanup (free_current_contents
, &expr
);
647 val
= evaluate_expression (expr
);
649 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
650 gdb_stdout
, 0, 0, 0, 0);
652 do_cleanups (old_chain
);
657 /* gdb_get_mem addr form size num aschar*/
658 /* dump a block of memory */
659 /* addr: address of data to dump */
660 /* form: a char indicating format */
661 /* size: size of each element; 1,2,4, or 8 bytes*/
662 /* num: the number of 'size' elements to return */
663 /* acshar: an optional ascii character to use in ASCII dump */
664 /* returns a list of 'num' elements followed by an optional */
667 gdb_get_mem (clientData
, interp
, argc
, argv
)
668 ClientData clientData
;
673 int size
, asize
, num
, i
, j
;
674 CORE_ADDR addr
, saved_addr
, ptr
;
676 struct type
*val_type
;
678 char c
, buff
[128], aschar
;
681 error ("wrong # args");
683 addr
= (CORE_ADDR
)strtoul(argv
[1],(char **)NULL
,0);
686 size
= (int)strtoul(argv
[3],(char **)NULL
,0);
687 num
= (int)strtoul(argv
[4],(char **)NULL
,0);
692 val_type
= builtin_type_char
;
696 val_type
= builtin_type_short
;
700 val_type
= builtin_type_int
;
704 val_type
= builtin_type_long_long
;
708 val_type
= builtin_type_char
;
712 for (i
=0; i
< num
; i
++)
714 vptr
= value_at (val_type
, addr
, (asection
*)NULL
);
715 print_scalar_formatted (VALUE_CONTENTS(vptr
), val_type
, format
, asize
, gdb_stdout
);
716 fputs_unfiltered (" ", gdb_stdout
);
722 val_type
= builtin_type_char
;
726 for (j
=0; j
< num
*size
; j
++)
728 c
= *(char *)VALUE_CONTENTS(value_at (val_type
, ptr
, (asection
*)NULL
));
729 if (c
< 32 || c
> 126)
738 fputs_unfiltered (buff
, gdb_stdout
);
745 /* This implements the TCL command `gdb_sourcelines', which returns a list of
746 all of the lines containing executable code for the specified source file
747 (ie: lines where you can put breakpoints). */
750 gdb_sourcelines (clientData
, interp
, argc
, argv
)
751 ClientData clientData
;
756 struct symtab
*symtab
;
757 struct linetable_entry
*le
;
761 error ("wrong # args");
763 symtab
= lookup_symtab (argv
[1]);
766 error ("No such file");
768 /* If there's no linetable, or no entries, then we are done. */
770 if (!symtab
->linetable
771 || symtab
->linetable
->nitems
== 0)
773 Tcl_DStringAppendElement (result_ptr
, "");
777 le
= symtab
->linetable
->item
;
778 nlines
= symtab
->linetable
->nitems
;
780 for (;nlines
> 0; nlines
--, le
++)
782 /* If the pc of this line is the same as the pc of the next line, then
785 && le
->pc
== (le
+ 1)->pc
)
788 dsprintf_append_element (result_ptr
, "%d", le
->line
);
795 map_arg_registers (argc
, argv
, func
, argp
)
798 void (*func
) PARAMS ((int regnum
, void *argp
));
803 /* Note that the test for a valid register must include checking the
804 reg_names array because NUM_REGS may be allocated for the union of the
805 register sets within a family of related processors. In this case, the
806 trailing entries of reg_names will change depending upon the particular
807 processor being debugged. */
809 if (argc
== 0) /* No args, just do all the regs */
813 && reg_names
[regnum
] != NULL
814 && *reg_names
[regnum
] != '\000';
821 /* Else, list of register #s, just do listed regs */
822 for (; argc
> 0; argc
--, argv
++)
824 regnum
= atoi (*argv
);
828 && reg_names
[regnum
] != NULL
829 && *reg_names
[regnum
] != '\000')
832 error ("bad register number");
839 get_register_name (regnum
, argp
)
841 void *argp
; /* Ignored */
843 Tcl_DStringAppendElement (result_ptr
, reg_names
[regnum
]);
846 /* This implements the TCL command `gdb_regnames', which returns a list of
847 all of the register names. */
850 gdb_regnames (clientData
, interp
, argc
, argv
)
851 ClientData clientData
;
859 return map_arg_registers (argc
, argv
, get_register_name
, NULL
);
862 #ifndef REGISTER_CONVERTIBLE
863 #define REGISTER_CONVERTIBLE(x) (0 != 0)
866 #ifndef REGISTER_CONVERT_TO_VIRTUAL
867 #define REGISTER_CONVERT_TO_VIRTUAL(x, y, z, a)
870 #ifndef INVALID_FLOAT
871 #define INVALID_FLOAT(x, y) (0 != 0)
875 get_register (regnum
, fp
)
879 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
880 char virtual_buffer
[MAX_REGISTER_VIRTUAL_SIZE
];
881 int format
= (int)fp
;
883 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
885 Tcl_DStringAppendElement (result_ptr
, "Optimized out");
889 /* Convert raw data to virtual format if necessary. */
891 if (REGISTER_CONVERTIBLE (regnum
))
893 REGISTER_CONVERT_TO_VIRTUAL (regnum
, REGISTER_VIRTUAL_TYPE (regnum
),
894 raw_buffer
, virtual_buffer
);
897 memcpy (virtual_buffer
, raw_buffer
, REGISTER_VIRTUAL_SIZE (regnum
));
902 printf_filtered ("0x");
903 for (j
= 0; j
< REGISTER_RAW_SIZE (regnum
); j
++)
905 register int idx
= TARGET_BYTE_ORDER
== BIG_ENDIAN
? j
906 : REGISTER_RAW_SIZE (regnum
) - 1 - j
;
907 printf_filtered ("%02x", (unsigned char)raw_buffer
[idx
]);
911 val_print (REGISTER_VIRTUAL_TYPE (regnum
), virtual_buffer
, 0,
912 gdb_stdout
, format
, 1, 0, Val_pretty_default
);
914 Tcl_DStringAppend (result_ptr
, " ", -1);
918 gdb_fetch_registers (clientData
, interp
, argc
, argv
)
919 ClientData clientData
;
927 error ("wrong # args");
935 return map_arg_registers (argc
, argv
, get_register
, (void *) format
);
938 /* This contains the previous values of the registers, since the last call to
939 gdb_changed_register_list. */
941 static char old_regs
[REGISTER_BYTES
];
944 register_changed_p (regnum
, argp
)
946 void *argp
; /* Ignored */
948 char raw_buffer
[MAX_REGISTER_RAW_SIZE
];
950 if (read_relative_register_raw_bytes (regnum
, raw_buffer
))
953 if (memcmp (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
954 REGISTER_RAW_SIZE (regnum
)) == 0)
957 /* Found a changed register. Save new value and return its number. */
959 memcpy (&old_regs
[REGISTER_BYTE (regnum
)], raw_buffer
,
960 REGISTER_RAW_SIZE (regnum
));
962 dsprintf_append_element (result_ptr
, "%d", regnum
);
966 gdb_changed_register_list (clientData
, interp
, argc
, argv
)
967 ClientData clientData
;
975 return map_arg_registers (argc
, argv
, register_changed_p
, NULL
);
978 /* This implements the TCL command `gdb_cmd', which sends its argument into
979 the GDB command scanner. */
982 gdb_cmd (clientData
, interp
, argc
, argv
)
983 ClientData clientData
;
988 Tcl_DString
*save_ptr
= NULL
;
991 error ("wrong # args");
996 /* for the load instruction (and possibly others later) we
997 set result_ptr to NULL so gdbtk_fputs() will not buffer
998 all the data until the command is finished. */
1000 if (strncmp("load ",argv
[1],5) == 0) {
1001 Tcl_DStringAppend (result_ptr
, "", -1);
1002 save_ptr
= result_ptr
;
1006 execute_command (argv
[1], 1);
1008 bpstat_do_actions (&stop_bpstat
);
1011 result_ptr
= save_ptr
;
1016 /* Client of call_wrapper - this routine performs the actual call to
1017 the client function. */
1019 struct wrapped_call_args
1030 struct wrapped_call_args
*args
;
1032 args
->val
= (*args
->func
) (args
->func
, args
->interp
, args
->argc
, args
->argv
);
1036 /* This routine acts as a top-level for all GDB code called by tcl/Tk. It
1037 handles cleanups, and calls to return_to_top_level (usually via error).
1038 This is necessary in order to prevent a longjmp out of the bowels of Tk,
1039 possibly leaving things in a bad state. Since this routine can be called
1040 recursively, it needs to save and restore the contents of the jmp_buf as
1044 call_wrapper (clientData
, interp
, argc
, argv
)
1045 ClientData clientData
;
1050 struct wrapped_call_args wrapped_args
;
1051 Tcl_DString result
, *old_result_ptr
;
1052 Tcl_DString error_string
, *old_error_string_ptr
;
1054 Tcl_DStringInit (&result
);
1055 old_result_ptr
= result_ptr
;
1056 result_ptr
= &result
;
1058 Tcl_DStringInit (&error_string
);
1059 old_error_string_ptr
= error_string_ptr
;
1060 error_string_ptr
= &error_string
;
1062 wrapped_args
.func
= (Tcl_CmdProc
*)clientData
;
1063 wrapped_args
.interp
= interp
;
1064 wrapped_args
.argc
= argc
;
1065 wrapped_args
.argv
= argv
;
1066 wrapped_args
.val
= 0;
1068 if (!catch_errors (wrapped_call
, &wrapped_args
, "", RETURN_MASK_ALL
))
1070 wrapped_args
.val
= TCL_ERROR
; /* Flag an error for TCL */
1072 gdb_flush (gdb_stderr
); /* Flush error output */
1074 gdb_flush (gdb_stdout
); /* Sometimes error output comes here as well */
1076 /* In case of an error, we may need to force the GUI into idle
1077 mode because gdbtk_call_command may have bombed out while in
1078 the command routine. */
1081 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1084 if (Tcl_DStringLength (&error_string
) == 0)
1086 Tcl_DStringResult (interp
, &result
);
1087 Tcl_DStringFree (&error_string
);
1089 else if (Tcl_DStringLength (&result
) == 0)
1091 Tcl_DStringResult (interp
, &error_string
);
1092 Tcl_DStringFree (&result
);
1096 Tcl_ResetResult (interp
);
1097 Tcl_AppendResult (interp
, Tcl_DStringValue (&result
),
1098 Tcl_DStringValue (&error_string
), (char *) NULL
);
1099 Tcl_DStringFree (&result
);
1100 Tcl_DStringFree (&error_string
);
1103 result_ptr
= old_result_ptr
;
1104 error_string_ptr
= old_error_string_ptr
;
1110 return wrapped_args
.val
;
1114 gdb_listfiles (clientData
, interp
, argc
, argv
)
1115 ClientData clientData
;
1120 struct objfile
*objfile
;
1121 struct partial_symtab
*psymtab
;
1122 struct symtab
*symtab
;
1124 ALL_PSYMTABS (objfile
, psymtab
)
1125 Tcl_DStringAppendElement (result_ptr
, psymtab
->filename
);
1127 ALL_SYMTABS (objfile
, symtab
)
1128 Tcl_DStringAppendElement (result_ptr
, symtab
->filename
);
1134 gdb_listfuncs (clientData
, interp
, argc
, argv
)
1135 ClientData clientData
;
1140 struct symtab
*symtab
;
1141 struct blockvector
*bv
;
1147 error ("wrong # args");
1149 symtab
= lookup_symtab (argv
[1]);
1152 error ("No such file");
1154 bv
= BLOCKVECTOR (symtab
);
1155 for (i
= GLOBAL_BLOCK
; i
<= STATIC_BLOCK
; i
++)
1157 b
= BLOCKVECTOR_BLOCK (bv
, i
);
1158 /* Skip the sort if this block is always sorted. */
1159 if (!BLOCK_SHOULD_SORT (b
))
1160 sort_block_syms (b
);
1161 for (j
= 0; j
< BLOCK_NSYMS (b
); j
++)
1163 sym
= BLOCK_SYM (b
, j
);
1164 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1166 Tcl_DStringAppendElement (result_ptr
, SYMBOL_NAME(sym
));
1174 gdb_stop (clientData
, interp
, argc
, argv
)
1175 ClientData clientData
;
1183 quit_flag
= 1; /* hope something sees this */
1188 /* Prepare to accept a new executable file. This is called when we
1189 want to clear away everything we know about the old file, without
1190 asking the user. The Tcl code will have already asked the user if
1191 necessary. After this is called, we should be able to run the
1192 `file' command without getting any questions. */
1195 gdb_clear_file (clientData
, interp
, argc
, argv
)
1196 ClientData clientData
;
1201 if (inferior_pid
!= 0 && target_has_execution
)
1204 target_detach (NULL
, 0);
1209 if (target_has_execution
)
1212 symbol_file_command (NULL
, 0);
1217 /* Ask the user to confirm an exit request. */
1220 gdb_confirm_quit (clientData
, interp
, argc
, argv
)
1221 ClientData clientData
;
1228 ret
= quit_confirm ();
1229 Tcl_DStringAppendElement (result_ptr
, ret
? "1" : "0");
1233 /* Quit without asking for confirmation. */
1236 gdb_force_quit (clientData
, interp
, argc
, argv
)
1237 ClientData clientData
;
1242 quit_force ((char *) NULL
, 1);
1246 /* This implements the TCL command `gdb_disassemble'. */
1249 gdbtk_dis_asm_read_memory (memaddr
, myaddr
, len
, info
)
1253 disassemble_info
*info
;
1255 extern struct target_ops exec_ops
;
1259 res
= xfer_memory (memaddr
, myaddr
, len
, 0, &exec_ops
);
1270 /* We need a different sort of line table from the normal one cuz we can't
1271 depend upon implicit line-end pc's for lines. This is because of the
1272 reordering we are about to do. */
1274 struct my_line_entry
{
1281 compare_lines (mle1p
, mle2p
)
1285 struct my_line_entry
*mle1
, *mle2
;
1288 mle1
= (struct my_line_entry
*) mle1p
;
1289 mle2
= (struct my_line_entry
*) mle2p
;
1291 val
= mle1
->line
- mle2
->line
;
1296 return mle1
->start_pc
- mle2
->start_pc
;
1300 gdb_disassemble (clientData
, interp
, argc
, argv
)
1301 ClientData clientData
;
1306 CORE_ADDR pc
, low
, high
;
1307 int mixed_source_and_assembly
;
1308 static disassemble_info di
;
1309 static int di_initialized
;
1311 if (! di_initialized
)
1313 INIT_DISASSEMBLE_INFO_NO_ARCH (di
, gdb_stdout
,
1314 (fprintf_ftype
) fprintf_unfiltered
);
1315 di
.flavour
= bfd_target_unknown_flavour
;
1316 di
.memory_error_func
= dis_asm_memory_error
;
1317 di
.print_address_func
= dis_asm_print_address
;
1321 di
.mach
= tm_print_insn_info
.mach
;
1322 if (TARGET_BYTE_ORDER
== BIG_ENDIAN
)
1323 di
.endian
= BFD_ENDIAN_BIG
;
1325 di
.endian
= BFD_ENDIAN_LITTLE
;
1327 if (argc
!= 3 && argc
!= 4)
1328 error ("wrong # args");
1330 if (strcmp (argv
[1], "source") == 0)
1331 mixed_source_and_assembly
= 1;
1332 else if (strcmp (argv
[1], "nosource") == 0)
1333 mixed_source_and_assembly
= 0;
1335 error ("First arg must be 'source' or 'nosource'");
1337 low
= parse_and_eval_address (argv
[2]);
1341 if (find_pc_partial_function (low
, NULL
, &low
, &high
) == 0)
1342 error ("No function contains specified address");
1345 high
= parse_and_eval_address (argv
[3]);
1347 /* If disassemble_from_exec == -1, then we use the following heuristic to
1348 determine whether or not to do disassembly from target memory or from the
1351 If we're debugging a local process, read target memory, instead of the
1352 exec file. This makes disassembly of functions in shared libs work
1355 Else, we're debugging a remote process, and should disassemble from the
1356 exec file for speed. However, this is no good if the target modifies its
1357 code (for relocation, or whatever).
1360 if (disassemble_from_exec
== -1)
1361 if (strcmp (target_shortname
, "child") == 0
1362 || strcmp (target_shortname
, "procfs") == 0
1363 || strcmp (target_shortname
, "vxprocess") == 0)
1364 disassemble_from_exec
= 0; /* It's a child process, read inferior mem */
1366 disassemble_from_exec
= 1; /* It's remote, read the exec file */
1368 if (disassemble_from_exec
)
1369 di
.read_memory_func
= gdbtk_dis_asm_read_memory
;
1371 di
.read_memory_func
= dis_asm_read_memory
;
1373 /* If just doing straight assembly, all we need to do is disassemble
1374 everything between low and high. If doing mixed source/assembly, we've
1375 got a totally different path to follow. */
1377 if (mixed_source_and_assembly
)
1378 { /* Come here for mixed source/assembly */
1379 /* The idea here is to present a source-O-centric view of a function to
1380 the user. This means that things are presented in source order, with
1381 (possibly) out of order assembly immediately following. */
1382 struct symtab
*symtab
;
1383 struct linetable_entry
*le
;
1386 struct my_line_entry
*mle
;
1387 struct symtab_and_line sal
;
1392 symtab
= find_pc_symtab (low
); /* Assume symtab is valid for whole PC range */
1397 /* First, convert the linetable to a bunch of my_line_entry's. */
1399 le
= symtab
->linetable
->item
;
1400 nlines
= symtab
->linetable
->nitems
;
1405 mle
= (struct my_line_entry
*) alloca (nlines
* sizeof (struct my_line_entry
));
1409 /* Copy linetable entries for this function into our data structure, creating
1410 end_pc's and setting out_of_order as appropriate. */
1412 /* First, skip all the preceding functions. */
1414 for (i
= 0; i
< nlines
- 1 && le
[i
].pc
< low
; i
++) ;
1416 /* Now, copy all entries before the end of this function. */
1419 for (; i
< nlines
- 1 && le
[i
].pc
< high
; i
++)
1421 if (le
[i
].line
== le
[i
+ 1].line
1422 && le
[i
].pc
== le
[i
+ 1].pc
)
1423 continue; /* Ignore duplicates */
1425 mle
[newlines
].line
= le
[i
].line
;
1426 if (le
[i
].line
> le
[i
+ 1].line
)
1428 mle
[newlines
].start_pc
= le
[i
].pc
;
1429 mle
[newlines
].end_pc
= le
[i
+ 1].pc
;
1433 /* If we're on the last line, and it's part of the function, then we need to
1434 get the end pc in a special way. */
1439 mle
[newlines
].line
= le
[i
].line
;
1440 mle
[newlines
].start_pc
= le
[i
].pc
;
1441 sal
= find_pc_line (le
[i
].pc
, 0);
1442 mle
[newlines
].end_pc
= sal
.end
;
1446 /* Now, sort mle by line #s (and, then by addresses within lines). */
1449 qsort (mle
, newlines
, sizeof (struct my_line_entry
), compare_lines
);
1451 /* Now, for each line entry, emit the specified lines (unless they have been
1452 emitted before), followed by the assembly code for that line. */
1454 next_line
= 0; /* Force out first line */
1455 for (i
= 0; i
< newlines
; i
++)
1457 /* Print out everything from next_line to the current line. */
1459 if (mle
[i
].line
>= next_line
)
1462 print_source_lines (symtab
, next_line
, mle
[i
].line
+ 1, 0);
1464 print_source_lines (symtab
, mle
[i
].line
, mle
[i
].line
+ 1, 0);
1466 next_line
= mle
[i
].line
+ 1;
1469 for (pc
= mle
[i
].start_pc
; pc
< mle
[i
].end_pc
; )
1472 fputs_unfiltered (" ", gdb_stdout
);
1473 print_address (pc
, gdb_stdout
);
1474 fputs_unfiltered (":\t ", gdb_stdout
);
1475 pc
+= (*tm_print_insn
) (pc
, &di
);
1476 fputs_unfiltered ("\n", gdb_stdout
);
1483 for (pc
= low
; pc
< high
; )
1486 fputs_unfiltered (" ", gdb_stdout
);
1487 print_address (pc
, gdb_stdout
);
1488 fputs_unfiltered (":\t ", gdb_stdout
);
1489 pc
+= (*tm_print_insn
) (pc
, &di
);
1490 fputs_unfiltered ("\n", gdb_stdout
);
1494 gdb_flush (gdb_stdout
);
1500 tk_command (cmd
, from_tty
)
1506 struct cleanup
*old_chain
;
1508 /* Catch case of no argument, since this will make the tcl interpreter dump core. */
1510 error_no_arg ("tcl command to interpret");
1512 retval
= Tcl_Eval (interp
, cmd
);
1514 result
= strdup (interp
->result
);
1516 old_chain
= make_cleanup (free
, result
);
1518 if (retval
!= TCL_OK
)
1521 printf_unfiltered ("%s\n", result
);
1523 do_cleanups (old_chain
);
1527 cleanup_init (ignored
)
1531 Tcl_DeleteInterp (interp
);
1535 /* Come here during long calculations to check for GUI events. Usually invoked
1536 via the QUIT macro. */
1539 gdbtk_interactive ()
1541 /* Tk_DoOneEvent (TK_DONT_WAIT|TK_IDLE_EVENTS); */
1544 /* Come here when there is activity on the X file descriptor. */
1550 /* Process pending events */
1552 while (Tcl_DoOneEvent (TCL_DONT_WAIT
|TCL_ALL_EVENTS
) != 0);
1557 /* For Cygwin32, we use a timer to periodically check for Windows
1558 messages. FIXME: It would be better to not poll, but to instead
1559 rewrite the target_wait routines to serve as input sources.
1560 Unfortunately, that will be a lot of work. */
1563 gdbtk_start_timer ()
1565 sigset_t nullsigmask
;
1566 struct sigaction action
;
1567 struct itimerval it
;
1569 sigemptyset (&nullsigmask
);
1571 action
.sa_handler
= x_event
;
1572 action
.sa_mask
= nullsigmask
;
1573 action
.sa_flags
= 0;
1574 sigaction (SIGALRM
, &action
, NULL
);
1576 it
.it_interval
.tv_sec
= 0;
1577 /* Check for messages twice a second. */
1578 it
.it_interval
.tv_usec
= 500 * 1000;
1579 it
.it_value
.tv_sec
= 0;
1580 it
.it_value
.tv_usec
= 500 * 1000;
1582 setitimer (ITIMER_REAL
, &it
, NULL
);
1588 sigset_t nullsigmask
;
1589 struct sigaction action
;
1590 struct itimerval it
;
1592 sigemptyset (&nullsigmask
);
1594 action
.sa_handler
= SIG_IGN
;
1595 action
.sa_mask
= nullsigmask
;
1596 action
.sa_flags
= 0;
1597 sigaction (SIGALRM
, &action
, NULL
);
1599 it
.it_interval
.tv_sec
= 0;
1600 it
.it_interval
.tv_usec
= 0;
1601 it
.it_value
.tv_sec
= 0;
1602 it
.it_value
.tv_usec
= 0;
1603 setitimer (ITIMER_REAL
, &it
, NULL
);
1608 /* This hook function is called whenever we want to wait for the
1612 gdbtk_wait (pid
, ourstatus
)
1614 struct target_waitstatus
*ourstatus
;
1617 struct sigaction action
;
1618 static sigset_t nullsigmask
= {0};
1622 /* Needed for SunOS 4.1.x */
1623 #define SA_RESTART 0
1626 action
.sa_handler
= x_event
;
1627 action
.sa_mask
= nullsigmask
;
1628 action
.sa_flags
= SA_RESTART
;
1629 sigaction(SIGIO
, &action
, NULL
);
1633 gdbtk_start_timer ();
1636 pid
= target_wait (pid
, ourstatus
);
1639 gdbtk_stop_timer ();
1643 action
.sa_handler
= SIG_IGN
;
1644 sigaction(SIGIO
, &action
, NULL
);
1650 /* This is called from execute_command, and provides a wrapper around
1651 various command routines in a place where both protocol messages and
1652 user input both flow through. Mostly this is used for indicating whether
1653 the target process is running or not.
1657 gdbtk_call_command (cmdblk
, arg
, from_tty
)
1658 struct cmd_list_element
*cmdblk
;
1663 if (cmdblk
->class == class_run
|| cmdblk
->class == class_trace
)
1666 Tcl_Eval (interp
, "gdbtk_tcl_busy");
1667 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1669 Tcl_Eval (interp
, "gdbtk_tcl_idle");
1672 (*cmdblk
->function
.cfunc
)(arg
, from_tty
);
1675 /* This function is called instead of gdb's internal command loop. This is the
1676 last chance to do anything before entering the main Tk event loop. */
1681 extern GDB_FILE
*instream
;
1683 /* We no longer want to use stdin as the command input stream */
1686 if (Tcl_Eval (interp
, "gdbtk_tcl_preloop") != TCL_OK
)
1690 /* Force errorInfo to be set up propertly. */
1691 Tcl_AddErrorInfo (interp
, "");
1693 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
1695 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
1697 fputs_unfiltered (msg
, gdb_stderr
);
1708 /* gdbtk_init installs this function as a final cleanup. */
1711 gdbtk_cleanup (dummy
)
1717 /* Initialize gdbtk. */
1720 gdbtk_init ( argv0
)
1723 struct cleanup
*old_chain
;
1724 char *lib
, *gdbtk_lib
, *gdbtk_lib_tmp
, *gdbtk_file
;
1727 struct sigaction action
;
1728 static sigset_t nullsigmask
= {0};
1731 /* start-sanitize-ide */
1732 struct ide_event_handle
*h
;
1735 /* end-sanitize-ide */
1738 /* If there is no DISPLAY environment variable, Tk_Init below will fail,
1739 causing gdb to abort. If instead we simply return here, gdb will
1740 gracefully degrade to using the command line interface. */
1743 if (getenv ("DISPLAY") == NULL
)
1747 old_chain
= make_cleanup (cleanup_init
, 0);
1749 /* First init tcl and tk. */
1750 Tcl_FindExecutable (argv0
);
1751 interp
= Tcl_CreateInterp ();
1754 error ("Tcl_CreateInterp failed");
1756 if (Tcl_Init(interp
) != TCL_OK
)
1757 error ("Tcl_Init failed: %s", interp
->result
);
1759 make_final_cleanup (gdbtk_cleanup
, NULL
);
1761 /* Initialize the Paths variable. */
1762 if (ide_initialize_paths (interp
, "gdbtcl") != TCL_OK
)
1763 error ("ide_initialize_paths failed: %s", interp
->result
);
1766 /* start-sanitize-ide */
1767 /* Find the directory where we expect to find idemanager. We ignore
1768 errors since it doesn't really matter if this fails. */
1769 libexecdir
= Tcl_GetVar2 (interp
, "Paths", "libexecdir", TCL_GLOBAL_ONLY
);
1773 h
= ide_event_init_from_environment (&errmsg
, libexecdir
);
1776 Tcl_AppendResult (interp
, "can't initialize event system: ", errmsg
,
1778 fprintf(stderr
, "WARNING: ide_event_init_client failed: %s\n", interp
->result
);
1780 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1784 if (ide_create_tclevent_command (interp
, h
) != TCL_OK
)
1785 error ("ide_create_tclevent_command failed: %s", interp
->result
);
1787 if (ide_create_edit_command (interp
, h
) != TCL_OK
)
1788 error ("ide_create_edit_command failed: %s", interp
->result
);
1790 if (ide_create_property_command (interp
, h
) != TCL_OK
)
1791 error ("ide_create_property_command failed: %s", interp
->result
);
1793 if (ide_create_build_command (interp
, h
) != TCL_OK
)
1794 error ("ide_create_build_command failed: %s", interp
->result
);
1796 if (ide_create_window_register_command (interp
, h
, "gdb-restore")
1798 error ("ide_create_window_register_command failed: %s",
1801 if (ide_create_window_command (interp
, h
) != TCL_OK
)
1802 error ("ide_create_window_command failed: %s", interp
->result
);
1804 if (ide_create_exit_command (interp
, h
) != TCL_OK
)
1805 error ("ide_create_exit_command failed: %s", interp
->result
);
1807 if (ide_create_help_command (interp
) != TCL_OK
)
1808 error ("ide_create_help_command failed: %s", interp
->result
);
1811 if (ide_initialize (interp, "gdb") != TCL_OK)
1812 error ("ide_initialize failed: %s", interp->result);
1815 Tcl_SetVar (interp
, "GDBTK_IDE", "1", 0);
1816 Tcl_SetVar (interp
, "IDE", "1", TCL_GLOBAL_ONLY
);
1818 /* end-sanitize-ide */
1820 Tcl_SetVar (interp
, "GDBTK_IDE", "0", 0);
1823 /* We don't want to open the X connection until we've done all the
1824 IDE initialization. Otherwise, goofy looking unfinished windows
1825 pop up when ILU drops into the TCL event loop. */
1827 if (Tk_Init(interp
) != TCL_OK
)
1828 error ("Tk_Init failed: %s", interp
->result
);
1830 if (Itcl_Init(interp
) == TCL_ERROR
)
1831 error ("Itcl_Init failed: %s", interp
->result
);
1833 if (Tix_Init(interp
) != TCL_OK
)
1834 error ("Tix_Init failed: %s", interp
->result
);
1837 /* On Windows, create a sizebox widget command */
1838 if (ide_create_sizebox_command (interp
) != TCL_OK
)
1839 error ("sizebox creation failed");
1840 if (ide_create_winprint_command (interp
) != TCL_OK
)
1841 error ("windows print code initialization failed");
1842 /* start-sanitize-ide */
1843 /* An interface to ShellExecute. */
1844 if (ide_create_shell_execute_command (interp
) != TCL_OK
)
1845 error ("shell execute command initialization failed");
1848 Tcl_CreateCommand (interp
, "gdb_cmd", call_wrapper
, gdb_cmd
, NULL
);
1849 Tcl_CreateCommand (interp
, "gdb_loc", call_wrapper
, gdb_loc
, NULL
);
1850 Tcl_CreateCommand (interp
, "gdb_path_conv", call_wrapper
, gdb_path_conv
, NULL
);
1851 Tcl_CreateCommand (interp
, "gdb_sourcelines", call_wrapper
, gdb_sourcelines
,
1853 Tcl_CreateCommand (interp
, "gdb_listfiles", call_wrapper
, gdb_listfiles
,
1855 Tcl_CreateCommand (interp
, "gdb_listfuncs", call_wrapper
, gdb_listfuncs
,
1857 Tcl_CreateCommand (interp
, "gdb_get_mem", call_wrapper
, gdb_get_mem
,
1859 Tcl_CreateCommand (interp
, "gdb_stop", call_wrapper
, gdb_stop
, NULL
);
1860 Tcl_CreateCommand (interp
, "gdb_regnames", call_wrapper
, gdb_regnames
, NULL
);
1861 Tcl_CreateCommand (interp
, "gdb_fetch_registers", call_wrapper
,
1862 gdb_fetch_registers
, NULL
);
1863 Tcl_CreateCommand (interp
, "gdb_changed_register_list", call_wrapper
,
1864 gdb_changed_register_list
, NULL
);
1865 Tcl_CreateCommand (interp
, "gdb_disassemble", call_wrapper
,
1866 gdb_disassemble
, NULL
);
1867 Tcl_CreateCommand (interp
, "gdb_eval", call_wrapper
, gdb_eval
, NULL
);
1868 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_list", call_wrapper
,
1869 gdb_get_breakpoint_list
, NULL
);
1870 Tcl_CreateCommand (interp
, "gdb_get_breakpoint_info", call_wrapper
,
1871 gdb_get_breakpoint_info
, NULL
);
1872 Tcl_CreateCommand (interp
, "gdb_clear_file", call_wrapper
,
1873 gdb_clear_file
, NULL
);
1874 Tcl_CreateCommand (interp
, "gdb_confirm_quit", call_wrapper
,
1875 gdb_confirm_quit
, NULL
);
1876 Tcl_CreateCommand (interp
, "gdb_force_quit", call_wrapper
,
1877 gdb_force_quit
, NULL
);
1878 Tcl_CreateCommand (interp
, "gdb_target_has_execution",
1879 gdb_target_has_execution_command
,
1881 Tcl_CreateObjCommand (interp
, "gdb_load_info", gdb_load_info
, NULL
, NULL
);
1882 Tcl_CreateObjCommand (interp
, "gdb_get_locals", gdb_get_vars_command
,
1883 (ClientData
) 0, NULL
);
1884 Tcl_CreateObjCommand (interp
, "gdb_get_args", gdb_get_vars_command
,
1885 (ClientData
) 1, NULL
);
1886 Tcl_CreateObjCommand (interp
, "gdb_get_function", gdb_get_function_command
,
1888 Tcl_CreateObjCommand (interp
, "gdb_get_line", gdb_get_line_command
,
1890 Tcl_CreateObjCommand (interp
, "gdb_get_file", gdb_get_file_command
,
1892 Tcl_CreateObjCommand (interp
, "gdb_tracepoint_exists",
1893 gdb_tracepoint_exists_command
, NULL
, NULL
);
1894 Tcl_CreateObjCommand (interp
, "gdb_get_tracepoint_info",
1895 gdb_get_tracepoint_info
, NULL
, NULL
);
1896 Tcl_CreateObjCommand (interp
, "gdb_actions",
1897 gdb_actions_command
, NULL
, NULL
);
1898 Tcl_CreateObjCommand (interp
, "gdb_prompt",
1899 gdb_prompt_command
, NULL
, NULL
);
1901 command_loop_hook
= tk_command_loop
;
1902 print_frame_info_listing_hook
=
1903 (void (*) PARAMS ((struct symtab
*, int, int, int))) null_routine
;
1904 query_hook
= gdbtk_query
;
1905 flush_hook
= gdbtk_flush
;
1906 create_breakpoint_hook
= gdbtk_create_breakpoint
;
1907 delete_breakpoint_hook
= gdbtk_delete_breakpoint
;
1908 modify_breakpoint_hook
= gdbtk_modify_breakpoint
;
1909 interactive_hook
= gdbtk_interactive
;
1910 target_wait_hook
= gdbtk_wait
;
1911 call_command_hook
= gdbtk_call_command
;
1912 readline_begin_hook
= gdbtk_readline_begin
;
1913 readline_hook
= gdbtk_readline
;
1914 readline_end_hook
= gdbtk_readline_end
;
1915 ui_load_progress_hook
= gdbtk_load_hash
;
1916 create_tracepoint_hook
= gdbtk_create_tracepoint
;
1917 delete_tracepoint_hook
= gdbtk_delete_tracepoint
;
1920 /* Get the file descriptor for the X server */
1922 x_fd
= ConnectionNumber (Tk_Display (Tk_MainWindow (interp
)));
1924 /* Setup for I/O interrupts */
1926 action
.sa_mask
= nullsigmask
;
1927 action
.sa_flags
= 0;
1928 action
.sa_handler
= SIG_IGN
;
1929 sigaction(SIGIO
, &action
, NULL
);
1933 if (ioctl (x_fd
, FIOASYNC
, &i
))
1934 perror_with_name ("gdbtk_init: ioctl FIOASYNC failed");
1938 if (ioctl (x_fd
, SIOCSPGRP
, &i
))
1939 perror_with_name ("gdbtk_init: ioctl SIOCSPGRP failed");
1944 if (fcntl (x_fd
, F_SETOWN
, i
))
1945 perror_with_name ("gdbtk_init: fcntl F_SETOWN failed");
1946 #endif /* F_SETOWN */
1947 #endif /* !SIOCSPGRP */
1950 if (ioctl (x_fd
, I_SETSIG
, S_INPUT
|S_RDNORM
) < 0)
1951 perror_with_name ("gdbtk_init: ioctl I_SETSIG failed");
1954 #endif /* ifndef FIOASYNC */
1957 add_com ("tk", class_obscure
, tk_command
,
1958 "Send a command directly into tk.");
1960 Tcl_LinkVar (interp
, "disassemble-from-exec", (char *)&disassemble_from_exec
,
1963 /* find the gdb tcl library and source main.tcl */
1965 gdbtk_lib
= getenv ("GDBTK_LIBRARY");
1967 if (access ("gdbtcl/main.tcl", R_OK
) == 0)
1968 gdbtk_lib
= "gdbtcl";
1970 gdbtk_lib
= GDBTK_LIBRARY
;
1972 gdbtk_lib_tmp
= xstrdup (gdbtk_lib
);
1975 /* see if GDBTK_LIBRARY is a path list */
1976 lib
= strtok (gdbtk_lib_tmp
, GDBTK_PATH_SEP
);
1979 if (Tcl_VarEval (interp
, "lappend auto_path ", lib
, NULL
) != TCL_OK
)
1981 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
1986 gdbtk_file
= concat (lib
, "/main.tcl", (char *) NULL
);
1987 if (access (gdbtk_file
, R_OK
) == 0)
1990 Tcl_SetVar (interp
, "GDBTK_LIBRARY", lib
, 0);
1994 while ((lib
= strtok (NULL
, ":")) != NULL
);
1996 free (gdbtk_lib_tmp
);
2000 /* Try finding it with the auto path. */
2002 static const char script
[] ="\
2003 proc gdbtk_find_main {} {\n\
2004 global auto_path GDBTK_LIBRARY\n\
2005 foreach dir $auto_path {\n\
2006 set f [file join $dir main.tcl]\n\
2007 if {[file exists $f]} then {\n\
2008 set GDBTK_LIBRARY $dir\n\
2016 if (Tcl_GlobalEval (interp
, (char *) script
) != TCL_OK
)
2018 fputs_unfiltered (Tcl_GetVar (interp
, "errorInfo", 0), gdb_stderr
);
2022 if (interp
->result
[0] != '\0')
2024 gdbtk_file
= xstrdup (interp
->result
);
2031 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2032 if (getenv("GDBTK_LIBRARY"))
2034 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n",getenv("GDBTK_LIBRARY"));
2035 fprintf_unfiltered (stderr
,
2036 "Please set GDBTK_LIBRARY to a path that includes the GDB tcl files.\n");
2040 fprintf_unfiltered (stderr
, "Unable to find main.tcl in %s\n", GDBTK_LIBRARY
);
2041 fprintf_unfiltered (stderr
, "You might want to set GDBTK_LIBRARY\n");
2046 /* Defer setup of fputs_unfiltered_hook to near the end so that error messages
2047 prior to this point go to stdout/stderr. */
2049 fputs_unfiltered_hook
= gdbtk_fputs
;
2051 if (Tcl_EvalFile (interp
, gdbtk_file
) != TCL_OK
)
2055 /* Force errorInfo to be set up propertly. */
2056 Tcl_AddErrorInfo (interp
, "");
2058 msg
= Tcl_GetVar (interp
, "errorInfo", TCL_GLOBAL_ONLY
);
2060 fputs_unfiltered_hook
= NULL
; /* Force errors to stdout/stderr */
2063 MessageBox (NULL
, msg
, NULL
, MB_OK
| MB_ICONERROR
| MB_TASKMODAL
);
2065 fputs_unfiltered (msg
, gdb_stderr
);
2072 /* start-sanitize-ide */
2073 /* Don't do this until we have initialized. Otherwise, we may get a
2074 run command before we are ready for one. */
2075 if (ide_run_server_init (interp
, h
) != TCL_OK
)
2076 error ("ide_run_server_init failed: %s", interp
->result
);
2077 /* end-sanitize-ide */
2082 discard_cleanups (old_chain
);
2086 gdb_target_has_execution_command (clientData
, interp
, argc
, argv
)
2087 ClientData clientData
;
2094 if (target_has_execution
&& inferior_pid
!= 0)
2097 Tcl_SetIntObj (Tcl_GetObjResult (interp
), result
);
2101 /* gdb_load_info - returns information about the file about to be downloaded */
2104 gdb_load_info (clientData
, interp
, objc
, objv
)
2105 ClientData clientData
;
2108 Tcl_Obj
*CONST objv
[];
2111 struct cleanup
*old_cleanups
;
2117 char *filename
= Tcl_GetStringFromObj (objv
[1], NULL
);
2119 loadfile_bfd
= bfd_openr (filename
, gnutarget
);
2120 if (loadfile_bfd
== NULL
)
2122 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Open failed", -1));
2125 old_cleanups
= make_cleanup (bfd_close
, loadfile_bfd
);
2127 if (!bfd_check_format (loadfile_bfd
, bfd_object
))
2129 Tcl_SetObjResult (interp
, Tcl_NewStringObj ("Bad Object File", -1));
2133 for (s
= loadfile_bfd
->sections
; s
; s
= s
->next
)
2135 if (s
->flags
& SEC_LOAD
)
2137 bfd_size_type size
= bfd_get_section_size_before_reloc (s
);
2140 ob
[0] = Tcl_NewStringObj((char *)bfd_get_section_name(loadfile_bfd
, s
), -1);
2141 ob
[1] = Tcl_NewLongObj ((long)size
);
2142 res
[i
++] = Tcl_NewListObj (2, ob
);
2147 Tcl_SetObjResult (interp
, Tcl_NewListObj (i
, res
));
2148 do_cleanups (old_cleanups
);
2154 gdbtk_load_hash (section
, num
)
2160 sprintf (buf
, "download_hash %s %ld", section
, num
);
2161 result
= Tcl_Eval (interp
, buf
);
2165 /* gdb_get_vars_command -
2167 * Implements the "gdb_get_locals" and "gdb_get_args" tcl commands. This
2168 * function sets the Tcl interpreter's result to a list of variable names
2169 * depending on clientData. If clientData is one, the result is a list of
2170 * arguments; zero returns a list of locals -- all relative to the block
2171 * specified as an argument to the command. Valid commands include
2172 * anything decode_line_1 can handle (like "main.c:2", "*0x02020202",
2176 gdb_get_vars_command (clientData
, interp
, objc
, objv
)
2177 ClientData clientData
;
2180 Tcl_Obj
*CONST objv
[];
2183 struct symtabs_and_lines sals
;
2185 struct block
*block
;
2186 char **canonical
, *args
;
2187 int i
, nsyms
, arguments
;
2191 Tcl_AppendResult (interp
,
2192 "wrong # of args: should be \"",
2193 Tcl_GetStringFromObj (objv
[0], NULL
),
2194 " function:line|function|line|*addr\"");
2198 arguments
= (int) clientData
;
2199 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2200 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2201 if (sals
.nelts
== 0)
2203 Tcl_AppendResult (interp
,
2204 "error decoding line", NULL
);
2208 /* Initialize a list that will hold the results */
2209 result
= Tcl_NewListObj (0, NULL
);
2211 /* Resolve all line numbers to PC's */
2212 for (i
= 0; i
< sals
.nelts
; i
++)
2213 resolve_sal_pc (&sals
.sals
[i
]);
2215 block
= block_for_pc (sals
.sals
[0].pc
);
2218 nsyms
= BLOCK_NSYMS (block
);
2219 for (i
= 0; i
< nsyms
; i
++)
2221 sym
= BLOCK_SYM (block
, i
);
2222 switch (SYMBOL_CLASS (sym
)) {
2224 case LOC_UNDEF
: /* catches errors */
2225 case LOC_CONST
: /* constant */
2226 case LOC_STATIC
: /* static */
2227 case LOC_REGISTER
: /* register */
2228 case LOC_TYPEDEF
: /* local typedef */
2229 case LOC_LABEL
: /* local label */
2230 case LOC_BLOCK
: /* local function */
2231 case LOC_CONST_BYTES
: /* loc. byte seq. */
2232 case LOC_UNRESOLVED
: /* unresolved static */
2233 case LOC_OPTIMIZED_OUT
: /* optimized out */
2235 case LOC_ARG
: /* argument */
2236 case LOC_REF_ARG
: /* reference arg */
2237 case LOC_REGPARM
: /* register arg */
2238 case LOC_REGPARM_ADDR
: /* indirect register arg */
2239 case LOC_LOCAL_ARG
: /* stack arg */
2240 case LOC_BASEREG_ARG
: /* basereg arg */
2242 Tcl_ListObjAppendElement (interp
, result
,
2243 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2245 case LOC_LOCAL
: /* stack local */
2246 case LOC_BASEREG
: /* basereg local */
2248 Tcl_ListObjAppendElement (interp
, result
,
2249 Tcl_NewStringObj (SYMBOL_NAME (sym
), -1));
2253 if (BLOCK_FUNCTION (block
))
2256 block
= BLOCK_SUPERBLOCK (block
);
2259 Tcl_SetObjResult (interp
, result
);
2264 gdb_get_line_command (clientData
, interp
, objc
, objv
)
2265 ClientData clientData
;
2268 Tcl_Obj
*CONST objv
[];
2271 struct symtabs_and_lines sals
;
2272 char *args
, **canonical
;
2276 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2277 Tcl_GetStringFromObj (objv
[0], NULL
),
2282 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2283 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2284 if (sals
.nelts
== 1)
2286 Tcl_SetObjResult (interp
, Tcl_NewIntObj (sals
.sals
[0].line
));
2290 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2295 gdb_get_file_command (clientData
, interp
, objc
, objv
)
2296 ClientData clientData
;
2299 Tcl_Obj
*CONST objv
[];
2302 struct symtabs_and_lines sals
;
2303 char *args
, **canonical
;
2307 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2308 Tcl_GetStringFromObj (objv
[0], NULL
),
2313 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2314 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2315 if (sals
.nelts
== 1)
2317 Tcl_SetResult (interp
, sals
.sals
[0].symtab
->filename
, TCL_VOLATILE
);
2321 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2326 gdb_get_function_command (clientData
, interp
, objc
, objv
)
2327 ClientData clientData
;
2330 Tcl_Obj
*CONST objv
[];
2334 struct symtabs_and_lines sals
;
2335 char *args
, **canonical
;
2339 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2340 Tcl_GetStringFromObj (objv
[0], NULL
),
2345 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2346 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2347 if (sals
.nelts
== 1)
2349 resolve_sal_pc (&sals
.sals
[0]);
2350 find_pc_partial_function (sals
.sals
[0].pc
, &function
, NULL
, NULL
);
2351 if (function
!= NULL
)
2353 Tcl_SetResult (interp
, function
, TCL_VOLATILE
);
2358 Tcl_SetResult (interp
, "N/A", TCL_STATIC
);
2363 gdb_get_tracepoint_info (clientData
, interp
, objc
, objv
)
2364 ClientData clientData
;
2367 Tcl_Obj
*CONST objv
[];
2369 struct symtab_and_line sal
;
2370 struct command_line
*cmd
;
2372 struct tracepoint
*tp
;
2373 struct action_line
*al
;
2374 Tcl_Obj
*list
, *action_list
;
2378 error ("wrong # args");
2380 Tcl_GetIntFromObj (NULL
, objv
[1], &tpnum
);
2382 ALL_TRACEPOINTS (tp
)
2383 if (tp
->number
== tpnum
)
2387 error ("Tracepoint #%d does not exist", tpnum
);
2389 list
= Tcl_NewListObj (0, NULL
);
2390 if (tp
->source_file
!= NULL
)
2391 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tp
->source_file
, -1));
2393 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj ("N/A", -1));
2394 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->line_number
));
2395 /* the function part is not currently used by the frontend */
2396 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj ("function", -1));
2397 sprintf (tmp
, "0x%08x", tp
->address
);
2398 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewStringObj (tmp
, -1));
2399 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->enabled
));
2400 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->pass_count
));
2401 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->step_count
));
2402 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->thread
));
2403 Tcl_ListObjAppendElement (interp
, list
, Tcl_NewIntObj (tp
->hit_count
));
2405 /* Append a list of actions */
2406 action_list
= Tcl_NewListObj (0, NULL
);
2407 for (al
= tp
->actions
; al
!= NULL
; al
= al
->next
)
2409 Tcl_ListObjAppendElement (interp
, action_list
,
2410 Tcl_NewStringObj (al
->action
, -1));
2412 Tcl_ListObjAppendElement (interp
, list
, action_list
);
2414 Tcl_SetObjResult (interp
, list
);
2419 gdbtk_create_tracepoint (tp
)
2420 struct tracepoint
*tp
;
2422 tracepoint_notify (tp
, "create");
2426 gdbtk_delete_tracepoint (tp
)
2427 struct tracepoint
*tp
;
2429 tracepoint_notify (tp
, "delete");
2433 tracepoint_notify(tp
, action
)
2434 struct tracepoint
*tp
;
2441 /* We ensure that ACTION contains no special Tcl characters, so we
2443 if (tp
->source_file
!= NULL
)
2444 source
= tp
->source_file
;
2447 sprintf (buf
, "gdbtk_tcl_tracepoint %s %d 0x%lx %d {%s}", action
, tp
->number
,
2448 (long)tp
->address
, tp
->line_number
, source
);
2450 v
= Tcl_Eval (interp
, buf
);
2454 gdbtk_fputs (interp
->result
, gdb_stdout
);
2455 gdbtk_fputs ("\n", gdb_stdout
);
2459 /* returns -1 if not found, tracepoint # if found */
2461 tracepoint_exists (char * args
)
2463 struct tracepoint
*tp
;
2465 struct symtabs_and_lines sals
;
2469 sals
= decode_line_1 (&args
, 1, NULL
, 0, &canonical
);
2470 if (sals
.nelts
== 1)
2472 resolve_sal_pc (&sals
.sals
[0]);
2473 file
= xmalloc (strlen (sals
.sals
[0].symtab
->dirname
)
2474 + strlen (sals
.sals
[0].symtab
->filename
) + 1);
2477 strcpy (file
, sals
.sals
[0].symtab
->dirname
);
2478 strcat (file
, sals
.sals
[0].symtab
->filename
);
2480 ALL_TRACEPOINTS (tp
)
2482 if (tp
->address
== sals
.sals
[0].pc
)
2483 result
= tp
->number
;
2484 else if (tp
->source_file
!= NULL
2485 && strcmp (tp
->source_file
, file
) == 0
2486 && sals
.sals
[0].line
== tp
->line_number
)
2488 result
= tp
->number
;
2498 gdb_actions_command (clientData
, interp
, objc
, objv
)
2499 ClientData clientData
;
2502 Tcl_Obj
*CONST objv
[];
2504 struct tracepoint
*tp
;
2506 int nactions
, i
, len
;
2507 char *number
, *args
, *action
;
2508 struct action_line
*next
= NULL
, *temp
;
2512 Tcl_AppendResult (interp
, "wrong # args: should be: \"",
2513 Tcl_GetStringFromObj (objv
[0], NULL
),
2514 " number actions\"");
2518 args
= number
= Tcl_GetStringFromObj (objv
[1], NULL
);
2519 tp
= get_tracepoint_by_number (&args
);
2522 Tcl_AppendResult (interp
, "Tracepoint \"", number
, "\" does not exist");
2526 /* Free any existing actions */
2527 for (temp
= tp
->actions
; temp
!= NULL
; temp
= temp
->next
)
2530 free (temp
->action
);
2534 Tcl_ListObjGetElements (interp
, objv
[2], &nactions
, &actions
);
2535 for (i
= 0; i
< nactions
; i
++)
2537 temp
= xmalloc (sizeof (struct action_line
));
2539 action
= Tcl_GetStringFromObj (actions
[i
], &len
);
2540 temp
->action
= savestring (action
, len
);
2557 gdb_tracepoint_exists_command (clientData
, interp
, objc
, objv
)
2558 ClientData clientData
;
2561 Tcl_Obj
*CONST objv
[];
2567 Tcl_AppendResult (interp
, "wrong # of args: should be \"",
2568 Tcl_GetStringFromObj (objv
[0], NULL
),
2569 " function:line|function|line|*addr\"");
2573 args
= Tcl_GetStringFromObj (objv
[1], NULL
);
2575 Tcl_SetObjResult (interp
, Tcl_NewIntObj (tracepoint_exists (args
)));
2579 /* Return the prompt to the interpreter */
2581 gdb_prompt_command (clientData
, interp
, objc
, objv
)
2582 ClientData clientData
;
2585 Tcl_Obj
*CONST objv
[];
2587 Tcl_SetResult (interp
, get_prompt (), TCL_VOLATILE
);
2591 /* Come here during initialize_all_files () */
2594 _initialize_gdbtk ()
2598 /* Tell the rest of the world that Gdbtk is now set up. */
2600 init_ui_hook
= gdbtk_init
;