Commit | Line | Data |
---|---|---|
f377b406 | 1 | /* TUI display locator. |
f33c6cbf | 2 | |
b811d2c2 | 3 | Copyright (C) 1998-2020 Free Software Foundation, Inc. |
f33c6cbf | 4 | |
f377b406 SC |
5 | Contributed by Hewlett-Packard Company. |
6 | ||
7 | This file is part of GDB. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
f377b406 SC |
12 | (at your option) any later version. |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
23 | #include "symtab.h" | |
24 | #include "breakpoint.h" | |
25 | #include "frame.h" | |
75fd9bc1 | 26 | #include "command.h" |
50265402 SC |
27 | #include "inferior.h" |
28 | #include "target.h" | |
7563e053 | 29 | #include "top.h" |
50f182aa | 30 | #include "gdb-demangle.h" |
56d397a3 | 31 | #include "source.h" |
d7b2e967 AC |
32 | #include "tui/tui.h" |
33 | #include "tui/tui-data.h" | |
34 | #include "tui/tui-stack.h" | |
35 | #include "tui/tui-wingeneral.h" | |
36 | #include "tui/tui-source.h" | |
37 | #include "tui/tui-winsource.h" | |
38 | #include "tui/tui-file.h" | |
c906108c | 39 | |
6a83354a | 40 | #include "gdb_curses.h" |
c906108c | 41 | |
973961bd TT |
42 | #define PROC_PREFIX "In: " |
43 | #define LINE_PREFIX "L" | |
44 | #define PC_PREFIX "PC: " | |
45 | ||
e555083f TT |
46 | /* Strings to display in the TUI status line. */ |
47 | #define SINGLE_KEY "(SingleKey)" | |
48 | ||
973961bd TT |
49 | /* Minimum/Maximum length of some fields displayed in the TUI status |
50 | line. */ | |
51 | #define MIN_LINE_WIDTH 4 /* Use at least 4 digits for line | |
52 | numbers. */ | |
53 | #define MIN_PROC_WIDTH 12 | |
54 | #define MAX_TARGET_WIDTH 10 | |
55 | #define MAX_PID_WIDTH 19 | |
56 | ||
f2dda477 TT |
57 | static struct tui_locator_window _locator; |
58 | ||
7d6dd1e9 | 59 | \f |
c906108c | 60 | |
f2dda477 TT |
61 | /* Accessor for the locator win info. Answers a pointer to the static |
62 | locator win info struct. */ | |
63 | struct tui_locator_window * | |
64 | tui_locator_win_info_ptr (void) | |
65 | { | |
66 | return &_locator; | |
67 | } | |
68 | ||
71a25ed2 TT |
69 | std::string |
70 | tui_locator_window::make_status_line () const | |
50265402 | 71 | { |
71a25ed2 | 72 | char line_buf[50]; |
a42a37b7 | 73 | int status_size; |
f8532154 | 74 | int proc_width; |
5b6fe301 | 75 | const char *pid_name; |
50265402 SC |
76 | int target_width; |
77 | int pid_width; | |
78 | int line_width; | |
50265402 | 79 | |
a068643d | 80 | std::string pid_name_holder; |
d7e15655 | 81 | if (inferior_ptid == null_ptid) |
50265402 SC |
82 | pid_name = "No process"; |
83 | else | |
a068643d TT |
84 | { |
85 | pid_name_holder = target_pid_to_str (inferior_ptid); | |
86 | pid_name = pid_name_holder.c_str (); | |
87 | } | |
50265402 SC |
88 | |
89 | target_width = strlen (target_shortname); | |
90 | if (target_width > MAX_TARGET_WIDTH) | |
91 | target_width = MAX_TARGET_WIDTH; | |
92 | ||
93 | pid_width = strlen (pid_name); | |
94 | if (pid_width > MAX_PID_WIDTH) | |
95 | pid_width = MAX_PID_WIDTH; | |
a42a37b7 | 96 | |
71a25ed2 | 97 | status_size = width; |
50265402 SC |
98 | |
99 | /* Translate line number and obtain its size. */ | |
71a25ed2 TT |
100 | if (line_no > 0) |
101 | xsnprintf (line_buf, sizeof (line_buf), "%d", line_no); | |
50265402 SC |
102 | else |
103 | strcpy (line_buf, "??"); | |
104 | line_width = strlen (line_buf); | |
105 | if (line_width < MIN_LINE_WIDTH) | |
106 | line_width = MIN_LINE_WIDTH; | |
107 | ||
108 | /* Translate PC address. */ | |
71a25ed2 TT |
109 | std::string pc_out (gdbarch |
110 | ? paddress (gdbarch, addr) | |
e2a678a5 | 111 | : "??"); |
d7e74731 PA |
112 | const char *pc_buf = pc_out.c_str (); |
113 | int pc_width = pc_out.size (); | |
114 | ||
50265402 SC |
115 | /* First determine the amount of proc name width we have available. |
116 | The +1 are for a space separator between fields. | |
117 | The -1 are to take into account the \0 counted by sizeof. */ | |
118 | proc_width = (status_size | |
119 | - (target_width + 1) | |
120 | - (pid_width + 1) | |
121 | - (sizeof (PROC_PREFIX) - 1 + 1) | |
122 | - (sizeof (LINE_PREFIX) - 1 + line_width + 1) | |
123 | - (sizeof (PC_PREFIX) - 1 + pc_width + 1) | |
6d012f14 | 124 | - (tui_current_key_mode == TUI_SINGLE_KEY_MODE |
50265402 SC |
125 | ? (sizeof (SINGLE_KEY) - 1 + 1) |
126 | : 0)); | |
127 | ||
128 | /* If there is no room to print the function name, try by removing | |
129 | some fields. */ | |
130 | if (proc_width < MIN_PROC_WIDTH) | |
131 | { | |
132 | proc_width += target_width + 1; | |
133 | target_width = 0; | |
134 | if (proc_width < MIN_PROC_WIDTH) | |
135 | { | |
136 | proc_width += pid_width + 1; | |
137 | pid_width = 0; | |
138 | if (proc_width <= MIN_PROC_WIDTH) | |
139 | { | |
140 | proc_width += pc_width + sizeof (PC_PREFIX) - 1 + 1; | |
141 | pc_width = 0; | |
142 | if (proc_width < 0) | |
143 | { | |
144 | proc_width += line_width + sizeof (LINE_PREFIX) - 1 + 1; | |
145 | line_width = 0; | |
146 | if (proc_width < 0) | |
147 | proc_width = 0; | |
148 | } | |
149 | } | |
150 | } | |
151 | } | |
152 | ||
1cc6d956 | 153 | /* Now create the locator line from the string version of the |
f8532154 TT |
154 | elements. */ |
155 | string_file string; | |
50265402 SC |
156 | |
157 | if (target_width > 0) | |
f8532154 | 158 | string.printf ("%*.*s ", -target_width, target_width, target_shortname); |
50265402 | 159 | if (pid_width > 0) |
f8532154 TT |
160 | string.printf ("%*.*s ", -pid_width, pid_width, pid_name); |
161 | ||
50265402 | 162 | /* Show whether we are in SingleKey mode. */ |
6d012f14 | 163 | if (tui_current_key_mode == TUI_SINGLE_KEY_MODE) |
50265402 | 164 | { |
f8532154 TT |
165 | string.puts (SINGLE_KEY); |
166 | string.puts (" "); | |
50265402 SC |
167 | } |
168 | ||
1cc6d956 | 169 | /* Procedure/class name. */ |
50265402 SC |
170 | if (proc_width > 0) |
171 | { | |
9923f347 | 172 | if (proc_name.size () > proc_width) |
f8532154 | 173 | string.printf ("%s%*.*s* ", PROC_PREFIX, |
9923f347 | 174 | 1 - proc_width, proc_width - 1, proc_name.c_str ()); |
50265402 | 175 | else |
f8532154 | 176 | string.printf ("%s%*.*s ", PROC_PREFIX, |
9923f347 | 177 | -proc_width, proc_width, proc_name.c_str ()); |
50265402 SC |
178 | } |
179 | ||
180 | if (line_width > 0) | |
f8532154 TT |
181 | string.printf ("%s%*.*s ", LINE_PREFIX, |
182 | -line_width, line_width, line_buf); | |
50265402 SC |
183 | if (pc_width > 0) |
184 | { | |
f8532154 TT |
185 | string.puts (PC_PREFIX); |
186 | string.puts (pc_buf); | |
50265402 | 187 | } |
50265402 | 188 | |
f8532154 TT |
189 | if (string.size () < status_size) |
190 | string.puts (n_spaces (status_size - string.size ())); | |
191 | else if (string.size () > status_size) | |
192 | string.string ().erase (status_size, string.size ()); | |
193 | ||
194 | return std::move (string.string ()); | |
50265402 SC |
195 | } |
196 | ||
1cc6d956 MS |
197 | /* Get a printable name for the function at the address. The symbol |
198 | name is demangled if demangling is turned on. Returns a pointer to | |
199 | a static area holding the result. */ | |
5564c769 SC |
200 | static char* |
201 | tui_get_function_from_frame (struct frame_info *fi) | |
202 | { | |
203 | static char name[256]; | |
d7e74731 | 204 | string_file stream; |
5564c769 | 205 | |
22e722e1 | 206 | print_address_symbolic (get_frame_arch (fi), get_frame_pc (fi), |
d7e74731 | 207 | &stream, demangle, ""); |
5564c769 | 208 | |
1cc6d956 MS |
209 | /* Use simple heuristics to isolate the function name. The symbol |
210 | can be demangled and we can have function parameters. Remove | |
211 | them because the status line is too short to display them. */ | |
d7e74731 PA |
212 | const char *d = stream.c_str (); |
213 | if (*d == '<') | |
214 | d++; | |
215 | strncpy (name, d, sizeof (name) - 1); | |
4e2af517 | 216 | name[sizeof (name) - 1] = 0; |
d7e74731 PA |
217 | |
218 | char *p = strchr (name, '('); | |
5564c769 SC |
219 | if (!p) |
220 | p = strchr (name, '>'); | |
221 | if (p) | |
222 | *p = 0; | |
223 | p = strchr (name, '+'); | |
224 | if (p) | |
225 | *p = 0; | |
5564c769 SC |
226 | return name; |
227 | } | |
c906108c | 228 | |
c906108c | 229 | void |
99ab33fb | 230 | tui_locator_window::rerender () |
c906108c | 231 | { |
99ab33fb | 232 | if (handle != NULL) |
c906108c | 233 | { |
71a25ed2 | 234 | std::string string = make_status_line (); |
7523da63 TT |
235 | scrollok (handle.get (), FALSE); |
236 | wmove (handle.get (), 0, 0); | |
cae3f17b JB |
237 | /* We ignore the return value from wstandout and wstandend, casting |
238 | them to void in order to avoid a compiler warning. The warning | |
239 | itself was introduced by a patch to ncurses 5.7 dated 2009-08-29, | |
240 | changing these macro to expand to code that causes the compiler | |
241 | to generate an unused-value warning. */ | |
7523da63 TT |
242 | (void) wstandout (handle.get ()); |
243 | waddstr (handle.get (), string.c_str ()); | |
244 | wclrtoeol (handle.get ()); | |
245 | (void) wstandend (handle.get ()); | |
99ab33fb | 246 | refresh_window (); |
7523da63 | 247 | wmove (handle.get (), 0, 0); |
c906108c | 248 | } |
50265402 | 249 | } |
c906108c | 250 | |
e594a5d1 TT |
251 | /* See tui-stack.h. */ |
252 | ||
253 | void | |
254 | tui_locator_window::set_locator_fullname (const char *fullname) | |
2e17b763 | 255 | { |
9923f347 | 256 | full_name = fullname; |
900ac242 | 257 | rerender (); |
2e17b763 | 258 | } |
c906108c | 259 | |
e594a5d1 | 260 | /* See tui-stack.h. */ |
b5fca6d7 | 261 | |
e594a5d1 TT |
262 | bool |
263 | tui_locator_window::set_locator_info (struct gdbarch *gdbarch_in, | |
0ab92974 TT |
264 | const struct symtab_and_line &sal, |
265 | const char *procname) | |
c906108c | 266 | { |
e594a5d1 | 267 | bool locator_changed_p = false; |
7d6dd1e9 | 268 | |
0ab92974 | 269 | gdb_assert (procname != NULL); |
b5fca6d7 | 270 | |
0ab92974 TT |
271 | const char *fullname = (sal.symtab == nullptr |
272 | ? "??" | |
273 | : symtab_to_fullname (sal.symtab)); | |
b5fca6d7 | 274 | |
9923f347 | 275 | locator_changed_p |= proc_name != procname; |
0ab92974 TT |
276 | locator_changed_p |= sal.line != line_no; |
277 | locator_changed_p |= sal.pc != addr; | |
e594a5d1 | 278 | locator_changed_p |= gdbarch_in != gdbarch; |
9923f347 | 279 | locator_changed_p |= full_name != fullname; |
b5fca6d7 | 280 | |
9923f347 | 281 | proc_name = procname; |
0ab92974 TT |
282 | line_no = sal.line; |
283 | addr = sal.pc; | |
e594a5d1 TT |
284 | gdbarch = gdbarch_in; |
285 | set_locator_fullname (fullname); | |
b5fca6d7 PP |
286 | |
287 | return locator_changed_p; | |
c7c228ed | 288 | } |
c906108c | 289 | |
56d397a3 | 290 | /* Update only the full_name portion of the locator. */ |
c906108c | 291 | void |
c1b167d7 | 292 | tui_update_locator_fullname (struct symtab *symtab) |
c906108c | 293 | { |
e594a5d1 TT |
294 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); |
295 | ||
c1b167d7 TT |
296 | const char *fullname; |
297 | if (symtab != nullptr) | |
298 | fullname = symtab_to_fullname (symtab); | |
299 | else | |
300 | fullname = "??"; | |
e594a5d1 | 301 | locator->set_locator_fullname (fullname); |
2e17b763 | 302 | } |
c906108c | 303 | |
b5fca6d7 | 304 | /* Function to print the frame information for the TUI. The windows are |
bbcbf914 | 305 | refreshed only if frame information has changed since the last refresh. |
b5fca6d7 | 306 | |
eb390f49 TT |
307 | Return true if frame information has changed (and windows |
308 | subsequently refreshed), false otherwise. */ | |
bbcbf914 | 309 | |
eb390f49 | 310 | bool |
47d3492a | 311 | tui_show_frame_info (struct frame_info *fi) |
c906108c | 312 | { |
e594a5d1 TT |
313 | bool locator_changed_p; |
314 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); | |
c906108c SS |
315 | |
316 | if (fi) | |
317 | { | |
51abb421 | 318 | symtab_and_line sal = find_frame_sal (fi); |
7d6dd1e9 | 319 | |
0ab92974 TT |
320 | const char *func_name; |
321 | /* find_frame_sal does not always set PC, but we want to ensure | |
322 | that it is available in the SAL. */ | |
323 | if (get_frame_pc_if_available (fi, &sal.pc)) | |
324 | func_name = tui_get_function_from_frame (fi); | |
e3eebbd7 | 325 | else |
0ab92974 TT |
326 | func_name = _("<unavailable>"); |
327 | ||
328 | locator_changed_p = locator->set_locator_info (get_frame_arch (fi), | |
329 | sal, func_name); | |
b5fca6d7 PP |
330 | |
331 | /* If the locator information has not changed, then frame information has | |
332 | not changed. If frame information has not changed, then the windows' | |
333 | contents will not change. So don't bother refreshing the windows. */ | |
334 | if (!locator_changed_p) | |
eb390f49 | 335 | return false; |
e3eebbd7 | 336 | |
ad54d15b | 337 | for (struct tui_source_window_base *win_info : tui_source_windows ()) |
c906108c | 338 | { |
1ae58f0c | 339 | win_info->maybe_update (fi, sal); |
7ba913dc | 340 | win_info->update_exec_info (); |
c906108c SS |
341 | } |
342 | } | |
343 | else | |
344 | { | |
0ab92974 TT |
345 | symtab_and_line sal {}; |
346 | ||
347 | locator_changed_p = locator->set_locator_info (NULL, sal, ""); | |
b5fca6d7 PP |
348 | |
349 | if (!locator_changed_p) | |
eb390f49 | 350 | return false; |
b5fca6d7 | 351 | |
ad54d15b | 352 | for (struct tui_source_window_base *win_info : tui_source_windows ()) |
ae4393e2 | 353 | win_info->erase_source_content (); |
c906108c | 354 | } |
eb390f49 TT |
355 | |
356 | return true; | |
7d6dd1e9 | 357 | } |
c906108c | 358 | |
99ab33fb TT |
359 | void |
360 | tui_show_locator_content () | |
361 | { | |
362 | struct tui_locator_window *locator = tui_locator_win_info_ptr (); | |
363 | locator->rerender (); | |
364 | } | |
365 | ||
12a8555a TT |
366 | /* Command to update the display with the current execution point. */ |
367 | static void | |
368 | tui_update_command (const char *arg, int from_tty) | |
369 | { | |
370 | execute_command ("frame 0", from_tty); | |
371 | } | |
372 | ||
6ba8e26f AC |
373 | /* Function to initialize gdb commands, for tui window stack |
374 | manipulation. */ | |
2c0b251b | 375 | |
6c265988 | 376 | void _initialize_tui_stack (); |
c906108c | 377 | void |
6c265988 | 378 | _initialize_tui_stack () |
c906108c | 379 | { |
9a2b4c1b MS |
380 | add_com ("update", class_tui, tui_update_command, |
381 | _("Update the source window and locator to " | |
283be8bf TT |
382 | "display the current execution point.\n\ |
383 | Usage: update")); | |
41783295 | 384 | } |