PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/src/freebsd/contrib/gdb/gdb/tui/tui-winsource.c

https://bitbucket.org/killerpenguinassassins/open_distrib_devel
C | 654 lines | 490 code | 91 blank | 73 comment | 104 complexity | cdc2383e271638a41c2b177622e09fdb MD5 | raw file
Possible License(s): CC0-1.0, MIT, LGPL-2.0, LGPL-3.0, WTFPL, GPL-2.0, BSD-2-Clause, AGPL-3.0, CC-BY-SA-3.0, MPL-2.0, JSON, BSD-3-Clause-No-Nuclear-License-2014, LGPL-2.1, CPL-1.0, AGPL-1.0, 0BSD, ISC, Apache-2.0, GPL-3.0, IPL-1.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /* TUI display source/assembly window.
  2. Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software
  3. Foundation, Inc.
  4. Contributed by Hewlett-Packard Company.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330,
  17. Boston, MA 02111-1307, USA. */
  18. #include "defs.h"
  19. #include <ctype.h>
  20. #include "symtab.h"
  21. #include "frame.h"
  22. #include "breakpoint.h"
  23. #include "value.h"
  24. #include "source.h"
  25. #include "tui/tui.h"
  26. #include "tui/tui-data.h"
  27. #include "tui/tui-stack.h"
  28. #include "tui/tui-win.h"
  29. #include "tui/tui-wingeneral.h"
  30. #include "tui/tui-winsource.h"
  31. #include "tui/tui-source.h"
  32. #include "tui/tui-disasm.h"
  33. #include "gdb_string.h"
  34. #include "gdb_curses.h"
  35. /* Function to display the "main" routine. */
  36. void
  37. tui_display_main (void)
  38. {
  39. if ((tui_source_windows ())->count > 0)
  40. {
  41. CORE_ADDR addr;
  42. addr = tui_get_begin_asm_address ();
  43. if (addr != (CORE_ADDR) 0)
  44. {
  45. struct symtab_and_line sal;
  46. tui_update_source_windows_with_addr (addr);
  47. sal = find_pc_line (addr, 0);
  48. if (sal.symtab)
  49. tui_update_locator_filename (sal.symtab->filename);
  50. else
  51. tui_update_locator_filename ("??");
  52. }
  53. }
  54. }
  55. /* Function to display source in the source window. This function
  56. initializes the horizontal scroll to 0. */
  57. void
  58. tui_update_source_window (struct tui_win_info * win_info, struct symtab *s,
  59. union tui_line_or_address line_or_addr, int noerror)
  60. {
  61. win_info->detail.source_info.horizontal_offset = 0;
  62. tui_update_source_window_as_is (win_info, s, line_or_addr, noerror);
  63. return;
  64. }
  65. /* Function to display source in the source/asm window. This function
  66. shows the source as specified by the horizontal offset. */
  67. void
  68. tui_update_source_window_as_is (struct tui_win_info * win_info, struct symtab *s,
  69. union tui_line_or_address line_or_addr, int noerror)
  70. {
  71. enum tui_status ret;
  72. if (win_info->generic.type == SRC_WIN)
  73. ret = tui_set_source_content (s, line_or_addr.line_no, noerror);
  74. else
  75. ret = tui_set_disassem_content (line_or_addr.addr);
  76. if (ret == TUI_FAILURE)
  77. {
  78. tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT);
  79. tui_clear_exec_info_content (win_info);
  80. }
  81. else
  82. {
  83. tui_update_breakpoint_info (win_info, 0);
  84. tui_show_source_content (win_info);
  85. tui_update_exec_info (win_info);
  86. if (win_info->generic.type == SRC_WIN)
  87. {
  88. struct symtab_and_line sal;
  89. sal.line = line_or_addr.line_no +
  90. (win_info->generic.content_size - 2);
  91. sal.symtab = s;
  92. set_current_source_symtab_and_line (&sal);
  93. /*
  94. ** If the focus was in the asm win, put it in the src
  95. ** win if we don't have a split layout
  96. */
  97. if (tui_win_with_focus () == TUI_DISASM_WIN &&
  98. tui_current_layout () != SRC_DISASSEM_COMMAND)
  99. tui_set_win_focus_to (TUI_SRC_WIN);
  100. }
  101. }
  102. return;
  103. }
  104. /* Function to ensure that the source and/or disassemly windows
  105. reflect the input address. */
  106. void
  107. tui_update_source_windows_with_addr (CORE_ADDR addr)
  108. {
  109. if (addr != 0)
  110. {
  111. struct symtab_and_line sal;
  112. union tui_line_or_address l;
  113. switch (tui_current_layout ())
  114. {
  115. case DISASSEM_COMMAND:
  116. case DISASSEM_DATA_COMMAND:
  117. tui_show_disassem (addr);
  118. break;
  119. case SRC_DISASSEM_COMMAND:
  120. tui_show_disassem_and_update_source (addr);
  121. break;
  122. default:
  123. sal = find_pc_line (addr, 0);
  124. l.line_no = sal.line;
  125. tui_show_symtab_source (sal.symtab, l, FALSE);
  126. break;
  127. }
  128. }
  129. else
  130. {
  131. int i;
  132. for (i = 0; i < (tui_source_windows ())->count; i++)
  133. {
  134. struct tui_win_info * win_info = (struct tui_win_info *) (tui_source_windows ())->list[i];
  135. tui_clear_source_content (win_info, EMPTY_SOURCE_PROMPT);
  136. tui_clear_exec_info_content (win_info);
  137. }
  138. }
  139. }
  140. /* Function to ensure that the source and/or disassemly windows
  141. reflect the input address. */
  142. void
  143. tui_update_source_windows_with_line (struct symtab *s, int line)
  144. {
  145. CORE_ADDR pc;
  146. union tui_line_or_address l;
  147. switch (tui_current_layout ())
  148. {
  149. case DISASSEM_COMMAND:
  150. case DISASSEM_DATA_COMMAND:
  151. find_line_pc (s, line, &pc);
  152. tui_update_source_windows_with_addr (pc);
  153. break;
  154. default:
  155. l.line_no = line;
  156. tui_show_symtab_source (s, l, FALSE);
  157. if (tui_current_layout () == SRC_DISASSEM_COMMAND)
  158. {
  159. find_line_pc (s, line, &pc);
  160. tui_show_disassem (pc);
  161. }
  162. break;
  163. }
  164. return;
  165. }
  166. void
  167. tui_clear_source_content (struct tui_win_info * win_info, int display_prompt)
  168. {
  169. if (win_info != NULL)
  170. {
  171. int i;
  172. win_info->generic.content_in_use = FALSE;
  173. tui_erase_source_content (win_info, display_prompt);
  174. for (i = 0; i < win_info->generic.content_size; i++)
  175. {
  176. struct tui_win_element * element =
  177. (struct tui_win_element *) win_info->generic.content[i];
  178. element->which_element.source.has_break = FALSE;
  179. element->which_element.source.is_exec_point = FALSE;
  180. }
  181. }
  182. }
  183. void
  184. tui_erase_source_content (struct tui_win_info * win_info, int display_prompt)
  185. {
  186. int x_pos;
  187. int half_width = (win_info->generic.width - 2) / 2;
  188. if (win_info->generic.handle != (WINDOW *) NULL)
  189. {
  190. werase (win_info->generic.handle);
  191. tui_check_and_display_highlight_if_needed (win_info);
  192. if (display_prompt == EMPTY_SOURCE_PROMPT)
  193. {
  194. char *no_src_str;
  195. if (win_info->generic.type == SRC_WIN)
  196. no_src_str = NO_SRC_STRING;
  197. else
  198. no_src_str = NO_DISASSEM_STRING;
  199. if (strlen (no_src_str) >= half_width)
  200. x_pos = 1;
  201. else
  202. x_pos = half_width - strlen (no_src_str);
  203. mvwaddstr (win_info->generic.handle,
  204. (win_info->generic.height / 2),
  205. x_pos,
  206. no_src_str);
  207. /* elz: added this function call to set the real contents of
  208. the window to what is on the screen, so that later calls
  209. to refresh, do display
  210. the correct stuff, and not the old image */
  211. tui_set_source_content_nil (win_info, no_src_str);
  212. }
  213. tui_refresh_win (&win_info->generic);
  214. }
  215. }
  216. /* Redraw the complete line of a source or disassembly window. */
  217. static void
  218. tui_show_source_line (struct tui_win_info * win_info, int lineno)
  219. {
  220. struct tui_win_element * line;
  221. int x, y;
  222. line = (struct tui_win_element *) win_info->generic.content[lineno - 1];
  223. if (line->which_element.source.is_exec_point)
  224. wattron (win_info->generic.handle, A_STANDOUT);
  225. mvwaddstr (win_info->generic.handle, lineno, 1,
  226. line->which_element.source.line);
  227. if (line->which_element.source.is_exec_point)
  228. wattroff (win_info->generic.handle, A_STANDOUT);
  229. /* Clear to end of line but stop before the border. */
  230. getyx (win_info->generic.handle, y, x);
  231. while (x + 1 < win_info->generic.width)
  232. {
  233. waddch (win_info->generic.handle, ' ');
  234. getyx (win_info->generic.handle, y, x);
  235. }
  236. }
  237. void
  238. tui_show_source_content (struct tui_win_info * win_info)
  239. {
  240. if (win_info->generic.content_size > 0)
  241. {
  242. int lineno;
  243. for (lineno = 1; lineno <= win_info->generic.content_size; lineno++)
  244. tui_show_source_line (win_info, lineno);
  245. }
  246. else
  247. tui_erase_source_content (win_info, TRUE);
  248. tui_check_and_display_highlight_if_needed (win_info);
  249. tui_refresh_win (&win_info->generic);
  250. win_info->generic.content_in_use = TRUE;
  251. }
  252. /* Scroll the source forward or backward horizontally. */
  253. void
  254. tui_horizontal_source_scroll (struct tui_win_info * win_info,
  255. enum tui_scroll_direction direction,
  256. int num_to_scroll)
  257. {
  258. if (win_info->generic.content != NULL)
  259. {
  260. int offset;
  261. struct symtab *s;
  262. struct symtab_and_line cursal = get_current_source_symtab_and_line ();
  263. if (cursal.symtab == (struct symtab *) NULL)
  264. s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));
  265. else
  266. s = cursal.symtab;
  267. if (direction == LEFT_SCROLL)
  268. offset = win_info->detail.source_info.horizontal_offset + num_to_scroll;
  269. else
  270. {
  271. if ((offset =
  272. win_info->detail.source_info.horizontal_offset - num_to_scroll) < 0)
  273. offset = 0;
  274. }
  275. win_info->detail.source_info.horizontal_offset = offset;
  276. tui_update_source_window_as_is (win_info, s,
  277. ((struct tui_win_element *)
  278. win_info->generic.content[0])->which_element.source.line_or_addr,
  279. FALSE);
  280. }
  281. return;
  282. }
  283. /* Set or clear the has_break flag in the line whose line is line_no. */
  284. void
  285. tui_set_is_exec_point_at (union tui_line_or_address l, struct tui_win_info * win_info)
  286. {
  287. int changed = 0;
  288. int i;
  289. tui_win_content content = (tui_win_content) win_info->generic.content;
  290. i = 0;
  291. while (i < win_info->generic.content_size)
  292. {
  293. int new_state;
  294. if (content[i]->which_element.source.line_or_addr.addr == l.addr)
  295. new_state = TRUE;
  296. else
  297. new_state = FALSE;
  298. if (new_state != content[i]->which_element.source.is_exec_point)
  299. {
  300. changed++;
  301. content[i]->which_element.source.is_exec_point = new_state;
  302. tui_show_source_line (win_info, i + 1);
  303. }
  304. i++;
  305. }
  306. if (changed)
  307. tui_refresh_win (&win_info->generic);
  308. }
  309. /* Update the execution windows to show the active breakpoints.
  310. This is called whenever a breakpoint is inserted, removed or
  311. has its state changed. */
  312. void
  313. tui_update_all_breakpoint_info (void)
  314. {
  315. struct tui_list *list = tui_source_windows ();
  316. int i;
  317. for (i = 0; i < list->count; i++)
  318. {
  319. struct tui_win_info * win = (struct tui_win_info *) list->list[i];
  320. if (tui_update_breakpoint_info (win, FALSE))
  321. {
  322. tui_update_exec_info (win);
  323. }
  324. }
  325. }
  326. /* Scan the source window and the breakpoints to update the
  327. has_break information for each line.
  328. Returns 1 if something changed and the execution window
  329. must be refreshed. */
  330. int
  331. tui_update_breakpoint_info (struct tui_win_info * win, int current_only)
  332. {
  333. int i;
  334. int need_refresh = 0;
  335. struct tui_source_info * src = &win->detail.source_info;
  336. for (i = 0; i < win->generic.content_size; i++)
  337. {
  338. struct breakpoint *bp;
  339. extern struct breakpoint *breakpoint_chain;
  340. int mode;
  341. struct tui_source_element* line;
  342. line = &((struct tui_win_element *) win->generic.content[i])->which_element.source;
  343. if (current_only && !line->is_exec_point)
  344. continue;
  345. /* Scan each breakpoint to see if the current line has something to
  346. do with it. Identify enable/disabled breakpoints as well as
  347. those that we already hit. */
  348. mode = 0;
  349. for (bp = breakpoint_chain;
  350. bp != (struct breakpoint *) NULL;
  351. bp = bp->next)
  352. {
  353. if ((win == TUI_SRC_WIN
  354. && bp->source_file
  355. && (strcmp (src->filename, bp->source_file) == 0)
  356. && bp->line_number == line->line_or_addr.line_no)
  357. || (win == TUI_DISASM_WIN
  358. && bp->loc->address == line->line_or_addr.addr))
  359. {
  360. if (bp->enable_state == bp_disabled)
  361. mode |= TUI_BP_DISABLED;
  362. else
  363. mode |= TUI_BP_ENABLED;
  364. if (bp->hit_count)
  365. mode |= TUI_BP_HIT;
  366. if (bp->cond)
  367. mode |= TUI_BP_CONDITIONAL;
  368. if (bp->type == bp_hardware_breakpoint)
  369. mode |= TUI_BP_HARDWARE;
  370. }
  371. }
  372. if (line->has_break != mode)
  373. {
  374. line->has_break = mode;
  375. need_refresh = 1;
  376. }
  377. }
  378. return need_refresh;
  379. }
  380. /* Function to initialize the content of the execution info window,
  381. based upon the input window which is either the source or
  382. disassembly window. */
  383. enum tui_status
  384. tui_set_exec_info_content (struct tui_win_info * win_info)
  385. {
  386. enum tui_status ret = TUI_SUCCESS;
  387. if (win_info->detail.source_info.execution_info != (struct tui_gen_win_info *) NULL)
  388. {
  389. struct tui_gen_win_info * exec_info_ptr = win_info->detail.source_info.execution_info;
  390. if (exec_info_ptr->content == NULL)
  391. exec_info_ptr->content =
  392. (void **) tui_alloc_content (win_info->generic.height,
  393. exec_info_ptr->type);
  394. if (exec_info_ptr->content != NULL)
  395. {
  396. int i;
  397. tui_update_breakpoint_info (win_info, 1);
  398. for (i = 0; i < win_info->generic.content_size; i++)
  399. {
  400. struct tui_win_element * element;
  401. struct tui_win_element * src_element;
  402. int mode;
  403. element = (struct tui_win_element *) exec_info_ptr->content[i];
  404. src_element = (struct tui_win_element *) win_info->generic.content[i];
  405. memset(element->which_element.simple_string, ' ',
  406. sizeof(element->which_element.simple_string));
  407. element->which_element.simple_string[TUI_EXECINFO_SIZE - 1] = 0;
  408. /* Now update the exec info content based upon the state
  409. of each line as indicated by the source content. */
  410. mode = src_element->which_element.source.has_break;
  411. if (mode & TUI_BP_HIT)
  412. element->which_element.simple_string[TUI_BP_HIT_POS] =
  413. (mode & TUI_BP_HARDWARE) ? 'H' : 'B';
  414. else if (mode & (TUI_BP_ENABLED | TUI_BP_DISABLED))
  415. element->which_element.simple_string[TUI_BP_HIT_POS] =
  416. (mode & TUI_BP_HARDWARE) ? 'h' : 'b';
  417. if (mode & TUI_BP_ENABLED)
  418. element->which_element.simple_string[TUI_BP_BREAK_POS] = '+';
  419. else if (mode & TUI_BP_DISABLED)
  420. element->which_element.simple_string[TUI_BP_BREAK_POS] = '-';
  421. if (src_element->which_element.source.is_exec_point)
  422. element->which_element.simple_string[TUI_EXEC_POS] = '>';
  423. }
  424. exec_info_ptr->content_size = win_info->generic.content_size;
  425. }
  426. else
  427. ret = TUI_FAILURE;
  428. }
  429. return ret;
  430. }
  431. void
  432. tui_show_exec_info_content (struct tui_win_info * win_info)
  433. {
  434. struct tui_gen_win_info * exec_info = win_info->detail.source_info.execution_info;
  435. int cur_line;
  436. werase (exec_info->handle);
  437. tui_refresh_win (exec_info);
  438. for (cur_line = 1; (cur_line <= exec_info->content_size); cur_line++)
  439. mvwaddstr (exec_info->handle,
  440. cur_line,
  441. 0,
  442. ((struct tui_win_element *)
  443. exec_info->content[cur_line - 1])->which_element.simple_string);
  444. tui_refresh_win (exec_info);
  445. exec_info->content_in_use = TRUE;
  446. }
  447. void
  448. tui_erase_exec_info_content (struct tui_win_info * win_info)
  449. {
  450. struct tui_gen_win_info * exec_info = win_info->detail.source_info.execution_info;
  451. werase (exec_info->handle);
  452. tui_refresh_win (exec_info);
  453. }
  454. void
  455. tui_clear_exec_info_content (struct tui_win_info * win_info)
  456. {
  457. win_info->detail.source_info.execution_info->content_in_use = FALSE;
  458. tui_erase_exec_info_content (win_info);
  459. return;
  460. }
  461. /* Function to update the execution info window. */
  462. void
  463. tui_update_exec_info (struct tui_win_info * win_info)
  464. {
  465. tui_set_exec_info_content (win_info);
  466. tui_show_exec_info_content (win_info);
  467. }
  468. enum tui_status
  469. tui_alloc_source_buffer (struct tui_win_info *win_info)
  470. {
  471. char *src_line_buf;
  472. int i, line_width, max_lines;
  473. enum tui_status ret = TUI_FAILURE;
  474. max_lines = win_info->generic.height; /* less the highlight box */
  475. line_width = win_info->generic.width - 1;
  476. /*
  477. ** Allocate the buffer for the source lines. Do this only once since they
  478. ** will be re-used for all source displays. The only other time this will
  479. ** be done is when a window's size changes.
  480. */
  481. if (win_info->generic.content == NULL)
  482. {
  483. src_line_buf = (char *) xmalloc ((max_lines * line_width) * sizeof (char));
  484. if (src_line_buf == (char *) NULL)
  485. fputs_unfiltered (
  486. "Unable to Allocate Memory for Source or Disassembly Display.\n",
  487. gdb_stderr);
  488. else
  489. {
  490. /* allocate the content list */
  491. if ((win_info->generic.content =
  492. (void **) tui_alloc_content (max_lines, SRC_WIN)) == NULL)
  493. {
  494. xfree (src_line_buf);
  495. src_line_buf = (char *) NULL;
  496. fputs_unfiltered (
  497. "Unable to Allocate Memory for Source or Disassembly Display.\n",
  498. gdb_stderr);
  499. }
  500. }
  501. for (i = 0; i < max_lines; i++)
  502. ((struct tui_win_element *)
  503. win_info->generic.content[i])->which_element.source.line =
  504. src_line_buf + (line_width * i);
  505. ret = TUI_SUCCESS;
  506. }
  507. else
  508. ret = TUI_SUCCESS;
  509. return ret;
  510. }
  511. /* Answer whether the a particular line number or address is displayed
  512. in the current source window. */
  513. int
  514. tui_line_is_displayed (int line, struct tui_win_info * win_info,
  515. int check_threshold)
  516. {
  517. int is_displayed = FALSE;
  518. int i, threshold;
  519. if (check_threshold)
  520. threshold = SCROLL_THRESHOLD;
  521. else
  522. threshold = 0;
  523. i = 0;
  524. while (i < win_info->generic.content_size - threshold && !is_displayed)
  525. {
  526. is_displayed = (((struct tui_win_element *)
  527. win_info->generic.content[i])->which_element.source.line_or_addr.line_no
  528. == (int) line);
  529. i++;
  530. }
  531. return is_displayed;
  532. }
  533. /* Answer whether the a particular line number or address is displayed
  534. in the current source window. */
  535. int
  536. tui_addr_is_displayed (CORE_ADDR addr, struct tui_win_info * win_info,
  537. int check_threshold)
  538. {
  539. int is_displayed = FALSE;
  540. int i, threshold;
  541. if (check_threshold)
  542. threshold = SCROLL_THRESHOLD;
  543. else
  544. threshold = 0;
  545. i = 0;
  546. while (i < win_info->generic.content_size - threshold && !is_displayed)
  547. {
  548. is_displayed = (((struct tui_win_element *)
  549. win_info->generic.content[i])->which_element.source.line_or_addr.addr
  550. == addr);
  551. i++;
  552. }
  553. return is_displayed;
  554. }
  555. /*****************************************
  556. ** STATIC LOCAL FUNCTIONS **
  557. ******************************************/