Re: PATCH: Problem union comparision in TUI

Andrew STUBBS
2005-10-19T16:22:11Z

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

Daniel Jacobowitz wrote:
> On Wed, Oct 19, 2005 at 10:48:53AM +0100, Andrew STUBBS wrote:
>
>>Is there any reason for using a union here? It's not like one value is
>>float and the other int - both are ints and the fact that you can't tell
>>which you are using shows nobody actually uses the distinction (unless I
>>have missed something). The union doesn't save any space, nor does it
>>make the code any more efficient.
>>
>>We could just use:
>>
>>CORE_ADDR line_or_address;
>>
>>and leave it at that.
>
>
> I'd rather that.

OK, how about the attached patch?

Andrew

[-- Attachment #2: tui-union-compare.patch --]
[-- Type: text/plain, Size: 19491 bytes --]

2005-10-19 Andrew Stubbs <andrew.stubbs@st.com>

* tui/tui-data.h (tui_line_or_address): Convert from union to a
single type.
(struct tui_source_element, struct tui_source_info): Update.
* tui/tui-data.c, tui/tui-disasm.c, tui/tui-source.c: Update.
* tui/tui-stack.c, tui/tui-win.c, tui-winsource.c: Update.
* tui/tui-winsource.h, tui/tui-layout.c, tui/tui-source.h: Update.

Index: src/gdb/tui/tui-data.h
===================================================================
--- src.orig/gdb/tui/tui-data.h 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-data.h 2005-10-19 15:36:05.000000000 +0100
@@ -146,12 +146,8 @@ enum tui_register_display_type
TUI_GENERAL_AND_SPECIAL_REGS
};

-/* Structure describing source line or line address */
-union tui_line_or_address
-{
- int line_no;
- CORE_ADDR addr;
-};
+/* Type describing source line or line address */
+typedef CORE_ADDR tui_line_or_address;

/* Current Layout definition */
struct tui_layout_def
@@ -166,7 +162,7 @@ struct tui_layout_def
struct tui_source_element
{
char *line;
- union tui_line_or_address line_or_addr;
+ tui_line_or_address line_or_addr;
int is_exec_point;
int has_break;
};
@@ -259,7 +255,7 @@ struct tui_source_info
/* Execution information window. */
struct tui_gen_win_info *execution_info;
int horizontal_offset; /* used for horizontal scroll */
- union tui_line_or_address start_line_or_addr;
+ tui_line_or_address start_line_or_addr;
char* filename;
};

Index: src/gdb/tui/tui-data.c
===================================================================
--- src.orig/gdb/tui/tui-data.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-data.c 2005-10-19 15:36:05.000000000 +0100
@@ -207,7 +207,7 @@ tui_clear_win_detail (struct tui_win_inf
{
case SRC_WIN:
case DISASSEM_WIN:
- win_info->detail.source_info.start_line_or_addr.addr = 0;
+ win_info->detail.source_info.start_line_or_addr = 0;
win_info->detail.source_info.horizontal_offset = 0;
break;
case CMD_WIN:
@@ -486,7 +486,7 @@ init_content_element (struct tui_win_ele
case SRC_WIN:
case DISASSEM_WIN:
element->which_element.source.line = (char *) NULL;
- element->which_element.source.line_or_addr.line_no = 0;
+ element->which_element.source.line_or_addr = 0;
element->which_element.source.is_exec_point = FALSE;
element->which_element.source.has_break = FALSE;
break;
@@ -537,7 +537,7 @@ init_win_info (struct tui_win_info * win
win_info->detail.source_info.execution_info = (struct tui_gen_win_info *) NULL;
win_info->detail.source_info.has_locator = FALSE;
win_info->detail.source_info.horizontal_offset = 0;
- win_info->detail.source_info.start_line_or_addr.addr = 0;
+ win_info->detail.source_info.start_line_or_addr = 0;
win_info->detail.source_info.filename = 0;
break;
case DATA_WIN:
Index: src/gdb/tui/tui-disasm.c
===================================================================
--- src.orig/gdb/tui/tui-disasm.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-disasm.c 2005-10-19 15:38:07.000000000 +0100
@@ -188,7 +188,7 @@ tui_set_disassem_content (CORE_ADDR pc)
if (ret != TUI_SUCCESS)
return ret;

- TUI_DISASM_WIN->detail.source_info.start_line_or_addr.addr = pc;
+ TUI_DISASM_WIN->detail.source_info.start_line_or_addr = pc;
cur_pc = (CORE_ADDR)
(((struct tui_win_element *) locator->content[0])->which_element.locator.addr);

@@ -249,7 +249,7 @@ tui_set_disassem_content (CORE_ADDR pc)
else
src->line[0] = '\0';

- src->line_or_addr.addr = asm_lines[i].addr;
+ src->line_or_addr = asm_lines[i].addr;
src->is_exec_point = asm_lines[i].addr == cur_pc;

/* See whether there is a breakpoint installed. */
@@ -270,9 +270,9 @@ tui_show_disassem (CORE_ADDR start_addr)
{
struct symtab *s = find_pc_symtab (start_addr);
struct tui_win_info * win_with_focus = tui_win_with_focus ();
- union tui_line_or_address val;
+ tui_line_or_address val;

- val.addr = start_addr;
+ val = start_addr;
tui_add_win_to_layout (DISASSEM_WIN);
tui_update_source_window (TUI_DISASM_WIN, s, val, FALSE);
/*
@@ -295,14 +295,14 @@ tui_show_disassem_and_update_source (COR
tui_show_disassem (start_addr);
if (tui_current_layout () == SRC_DISASSEM_COMMAND)
{
- union tui_line_or_address val;
+ tui_line_or_address val;

/*
** Update what is in the source window if it is displayed too,
** note that it follows what is in the disassembly window and visa-versa
*/
sal = find_pc_line (start_addr, 0);
- val.line_no = sal.line;
+ val = sal.line;
tui_update_source_window (TUI_SRC_WIN, sal.symtab, val, TRUE);
if (sal.symtab)
{
@@ -376,7 +376,7 @@ tui_vertical_disassem_scroll (enum tui_s
CORE_ADDR pc;
tui_win_content content;
struct symtab *s;
- union tui_line_or_address val;
+ tui_line_or_address val;
int max_lines, dir;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();

@@ -388,10 +388,10 @@ tui_vertical_disassem_scroll (enum tui_s

/* account for hilite */
max_lines = TUI_DISASM_WIN->generic.height - 2;
- pc = content[0]->which_element.source.line_or_addr.addr;
+ pc = content[0]->which_element.source.line_or_addr;
dir = (scroll_direction == FORWARD_SCROLL) ? max_lines : - max_lines;

- val.addr = tui_find_disassembly_address (pc, dir);
+ val = tui_find_disassembly_address (pc, dir);
tui_update_source_window_as_is (TUI_DISASM_WIN, s, val, FALSE);
}
}
Index: src/gdb/tui/tui-source.c
===================================================================
--- src.orig/gdb/tui/tui-source.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-source.c 2005-10-19 16:02:59.000000000 +0100
@@ -106,7 +106,7 @@ tui_set_source_content (struct symtab *s
stream = fdopen (desc, FOPEN_RT);
clearerr (stream);
cur_line = 0;
- cur_line_no = src->start_line_or_addr.line_no = line_no;
+ cur_line_no = src->start_line_or_addr = line_no;
if (offset > 0)
src_line = (char *) xmalloc (
(threshold + 1) * sizeof (char));
@@ -137,8 +137,7 @@ tui_set_source_content (struct symtab *s

/* Set whether element is the execution point and
whether there is a break point on it. */
- element->which_element.source.line_or_addr.line_no =
- cur_line_no;
+ element->which_element.source.line_or_addr = cur_line_no;
element->which_element.source.is_exec_point =
(strcmp (((struct tui_win_element *)
locator->content[0])->which_element.locator.file_name,
@@ -247,7 +246,7 @@ tui_set_source_content_nil (struct tui_w

struct tui_win_element * element =
(struct tui_win_element *) win_info->generic.content[curr_line];
- element->which_element.source.line_or_addr.line_no = 0;
+ element->which_element.source.line_or_addr = 0;
element->which_element.source.is_exec_point = FALSE;
element->which_element.source.has_break = FALSE;

@@ -295,7 +294,7 @@ tui_set_source_content_nil (struct tui_w
/* Function to display source in the source window. This function
initializes the horizontal scroll to 0. */
void
-tui_show_symtab_source (struct symtab *s, union tui_line_or_address line, int noerror)
+tui_show_symtab_source (struct symtab *s, tui_line_or_address line, int noerror)
{
TUI_SRC_WIN->detail.source_info.horizontal_offset = 0;
tui_update_source_window_as_is (TUI_SRC_WIN, s, line, noerror);
@@ -320,7 +319,7 @@ tui_vertical_source_scroll (enum tui_scr
{
if (TUI_SRC_WIN->generic.content != NULL)
{
- union tui_line_or_address l;
+ tui_line_or_address l;
struct symtab *s;
tui_win_content content = (tui_win_content) TUI_SRC_WIN->generic.content;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
@@ -332,21 +331,19 @@ tui_vertical_source_scroll (enum tui_scr

if (scroll_direction == FORWARD_SCROLL)
{
- l.line_no = content[0]->which_element.source.line_or_addr.line_no +
- num_to_scroll;
- if (l.line_no > s->nlines)
+ l = content[0]->which_element.source.line_or_addr + num_to_scroll;
+ if (l > s->nlines)
/*line = s->nlines - win_info->generic.content_size + 1; */
/*elz: fix for dts 23398 */
- l.line_no = content[0]->which_element.source.line_or_addr.line_no;
+ l = content[0]->which_element.source.line_or_addr;
}
else
{
- l.line_no = content[0]->which_element.source.line_or_addr.line_no -
- num_to_scroll;
- if (l.line_no <= 0)
- l.line_no = 1;
+ l = content[0]->which_element.source.line_or_addr - num_to_scroll;
+ if (l <= 0)
+ l = 1;
}

- print_source_lines (s, l.line_no, l.line_no + 1, 0);
+ print_source_lines (s, l, l + 1, 0);
}
}
Index: src/gdb/tui/tui-stack.c
===================================================================
--- src.orig/gdb/tui/tui-stack.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-stack.c 2005-10-19 16:03:56.000000000 +0100
@@ -364,14 +364,14 @@ tui_show_frame_info (struct frame_info *

if (win_info == TUI_SRC_WIN)
{
- union tui_line_or_address l;
- l.line_no = start_line;
+ tui_line_or_address l;
+ l = start_line;
if (!(source_already_displayed
&& tui_line_is_displayed (item->locator.line_no, win_info, TRUE)))
tui_update_source_window (win_info, sal.symtab, l, TRUE);
else
{
- l.line_no = item->locator.line_no;
+ l = item->locator.line_no;
tui_set_is_exec_point_at (l, win_info);
}
}
@@ -379,13 +379,13 @@ tui_show_frame_info (struct frame_info *
{
if (win_info == TUI_DISASM_WIN)
{
- union tui_line_or_address a;
- a.addr = low;
+ tui_line_or_address a;
+ a = low;
if (!tui_addr_is_displayed (item->locator.addr, win_info, TRUE))
tui_update_source_window (win_info, sal.symtab, a, TRUE);
else
{
- a.addr = item->locator.addr;
+ a = item->locator.addr;
tui_set_is_exec_point_at (a, win_info);
}
}
Index: src/gdb/tui/tui-win.c
===================================================================
--- src.orig/gdb/tui/tui-win.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-win.c 2005-10-19 16:04:50.000000000 +0100
@@ -1322,31 +1322,29 @@ make_visible_with_new_height (struct tui
tui_make_visible (win_info->detail.source_info.execution_info);
if (win_info->generic.content != NULL)
{
- union tui_line_or_address line_or_addr;
+ tui_line_or_address line_or_addr;
struct symtab_and_line cursal
= get_current_source_symtab_and_line ();

if (win_info->generic.type == SRC_WIN)
- line_or_addr.line_no =
- win_info->detail.source_info.start_line_or_addr.line_no;
+ line_or_addr = win_info->detail.source_info.start_line_or_addr;
else
- line_or_addr.addr =
- win_info->detail.source_info.start_line_or_addr.addr;
+ line_or_addr = win_info->detail.source_info.start_line_or_addr;
tui_free_win_content (&win_info->generic);
tui_update_source_window (win_info, cursal.symtab, line_or_addr, TRUE);
}
else if (deprecated_selected_frame != (struct frame_info *) NULL)
{
- union tui_line_or_address line;
+ tui_line_or_address line;
struct symtab_and_line cursal = get_current_source_symtab_and_line ();

s = find_pc_symtab (get_frame_pc (deprecated_selected_frame));
if (win_info->generic.type == SRC_WIN)
- line.line_no = cursal.line;
+ line = cursal.line;
else
{
- find_line_pc (s, cursal.line, &line.addr);
+ find_line_pc (s, cursal.line, &line);
}
tui_update_source_window (win_info, s, line, TRUE);
}
Index: src/gdb/tui/tui-winsource.c
===================================================================
--- src.orig/gdb/tui/tui-winsource.c 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-winsource.c 2005-10-19 15:44:22.000000000 +0100
@@ -71,7 +71,7 @@ tui_display_main (void)
initializes the horizontal scroll to 0. */
void
tui_update_source_window (struct tui_win_info * win_info, struct symtab *s,
- union tui_line_or_address line_or_addr, int noerror)
+ tui_line_or_address line_or_addr, int noerror)
{
win_info->detail.source_info.horizontal_offset = 0;
tui_update_source_window_as_is (win_info, s, line_or_addr, noerror);
@@ -84,14 +84,14 @@ tui_update_source_window (struct tui_win
shows the source as specified by the horizontal offset. */
void
tui_update_source_window_as_is (struct tui_win_info * win_info, struct symtab *s,
- union tui_line_or_address line_or_addr, int noerror)
+ tui_line_or_address line_or_addr, int noerror)
{
enum tui_status ret;

if (win_info->generic.type == SRC_WIN)
- ret = tui_set_source_content (s, line_or_addr.line_no, noerror);
+ ret = tui_set_source_content (s, line_or_addr, noerror);
else
- ret = tui_set_disassem_content (line_or_addr.addr);
+ ret = tui_set_disassem_content (line_or_addr);

if (ret == TUI_FAILURE)
{
@@ -107,8 +107,7 @@ tui_update_source_window_as_is (struct t
{
struct symtab_and_line sal;

- sal.line = line_or_addr.line_no +
- (win_info->generic.content_size - 2);
+ sal.line = line_or_addr + (win_info->generic.content_size - 2);
sal.symtab = s;
set_current_source_symtab_and_line (&sal);
/*
@@ -134,7 +133,7 @@ tui_update_source_windows_with_addr (COR
if (addr != 0)
{
struct symtab_and_line sal;
- union tui_line_or_address l;
+ tui_line_or_address l;

switch (tui_current_layout ())
{
@@ -147,7 +146,7 @@ tui_update_source_windows_with_addr (COR
break;
default:
sal = find_pc_line (addr, 0);
- l.line_no = sal.line;
+ l = sal.line;
tui_show_symtab_source (sal.symtab, l, FALSE);
break;
}
@@ -172,7 +171,7 @@ void
tui_update_source_windows_with_line (struct symtab *s, int line)
{
CORE_ADDR pc;
- union tui_line_or_address l;
+ tui_line_or_address l;

switch (tui_current_layout ())
{
@@ -182,7 +181,7 @@ tui_update_source_windows_with_line (str
tui_update_source_windows_with_addr (pc);
break;
default:
- l.line_no = line;
+ l = line;
tui_show_symtab_source (s, l, FALSE);
if (tui_current_layout () == SRC_DISASSEM_COMMAND)
{
@@ -336,7 +335,7 @@ tui_horizontal_source_scroll (struct tui

/* Set or clear the has_break flag in the line whose line is line_no. */
void
-tui_set_is_exec_point_at (union tui_line_or_address l, struct tui_win_info * win_info)
+tui_set_is_exec_point_at (tui_line_or_address l, struct tui_win_info * win_info)
{
int changed = 0;
int i;
@@ -347,7 +346,7 @@ tui_set_is_exec_point_at (union tui_line
{
int new_state;

- if (content[i]->which_element.source.line_or_addr.addr == l.addr)
+ if (content[i]->which_element.source.line_or_addr == l)
new_state = TRUE;
else
new_state = FALSE;
@@ -417,9 +416,9 @@ tui_update_breakpoint_info (struct tui_w
if ((win == TUI_SRC_WIN
&& bp->source_file
&& (strcmp (src->filename, bp->source_file) == 0)
- && bp->line_number == line->line_or_addr.line_no)
+ && bp->line_number == line->line_or_addr)
|| (win == TUI_DISASM_WIN
- && bp->loc->address == line->line_or_addr.addr))
+ && bp->loc->address == line->line_or_addr))
{
if (bp->enable_state == bp_disabled)
mode |= TUI_BP_DISABLED;
@@ -614,7 +613,7 @@ tui_line_is_displayed (int line, struct
while (i < win_info->generic.content_size - threshold && !is_displayed)
{
is_displayed = (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.line_no
+ win_info->generic.content[i])->which_element.source.line_or_addr
== (int) line);
i++;
}
@@ -640,7 +639,7 @@ tui_addr_is_displayed (CORE_ADDR addr, s
while (i < win_info->generic.content_size - threshold && !is_displayed)
{
is_displayed = (((struct tui_win_element *)
- win_info->generic.content[i])->which_element.source.line_or_addr.addr
+ win_info->generic.content[i])->which_element.source.line_or_addr
== addr);
i++;
}
Index: src/gdb/tui/tui-winsource.h
===================================================================
--- src.orig/gdb/tui/tui-winsource.h 2005-10-19 15:35:49.000000000 +0100
+++ src/gdb/tui/tui-winsource.h 2005-10-19 15:36:05.000000000 +0100
@@ -43,10 +43,10 @@ extern int tui_update_breakpoint_info (s
/* Function to display the "main" routine. */
extern void tui_display_main (void);
extern void tui_update_source_window (struct tui_win_info *, struct symtab *,
- union tui_line_or_address, int);
+ tui_line_or_address, int);
extern void tui_update_source_window_as_is (struct tui_win_info *,
struct symtab *,
- union tui_line_or_address, int);
+ tui_line_or_address, int);
extern void tui_update_source_windows_with_addr (CORE_ADDR);
extern void tui_update_source_windows_with_line (struct symtab *, int);
extern void tui_clear_source_content (struct tui_win_info *, int);
@@ -60,7 +60,7 @@ extern void tui_erase_exec_info_content
extern void tui_clear_exec_info_content (struct tui_win_info *);
extern void tui_update_exec_info (struct tui_win_info *);

-extern void tui_set_is_exec_point_at (union tui_line_or_address,
+extern void tui_set_is_exec_point_at (tui_line_or_address,
struct tui_win_info *);
extern enum tui_status tui_alloc_source_buffer (struct tui_win_info *);
extern int tui_line_is_displayed (int, struct tui_win_info *, int);
Index: src/gdb/tui/tui-layout.c
===================================================================
--- src.orig/gdb/tui/tui-layout.c 2005-02-15 15:49:27.000000000 +0000
+++ src/gdb/tui/tui-layout.c 2005-10-19 15:39:17.000000000 +0100
@@ -519,14 +519,14 @@ extract_display_start_addr (void)
case SRC_COMMAND:
case SRC_DATA_COMMAND:
find_line_pc (cursal.symtab,
- TUI_SRC_WIN->detail.source_info.start_line_or_addr.line_no,
+ TUI_SRC_WIN->detail.source_info.start_line_or_addr,
&pc);
addr = pc;
break;
case DISASSEM_COMMAND:
case SRC_DISASSEM_COMMAND:
case DISASSEM_DATA_COMMAND:
- addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr.addr;
+ addr = TUI_DISASM_WIN->detail.source_info.start_line_or_addr;
break;
default:
addr = 0;
Index: src/gdb/tui/tui-source.h
===================================================================
--- src.orig/gdb/tui/tui-source.h 2004-02-07 01:40:25.000000000 +0000
+++ src/gdb/tui/tui-source.h 2005-10-19 15:40:11.000000000 +0100
@@ -33,7 +33,7 @@ struct tui_win_info;
extern void tui_set_source_content_nil (struct tui_win_info *, char *);

extern enum tui_status tui_set_source_content (struct symtab *, int, int);
-extern void tui_show_symtab_source (struct symtab *, union tui_line_or_address, int);
+extern void tui_show_symtab_source (struct symtab *, tui_line_or_address, int);
extern int tui_source_is_displayed (char *);
extern void tui_vertical_source_scroll (enum tui_scroll_direction, int);