Skip to content

Commit

Permalink
scope - explicitly init global/static variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zhekov committed Jul 29, 2013
1 parent 4dc860d commit 015163d
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 65 deletions.
14 changes: 14 additions & 0 deletions scope/ChangeLog
@@ -1,3 +1,17 @@
2013-07-25 Dimitar Zhekov <dimitar.zhekov@gmail.com>

* src/break.c, src/conterm.c, src/debug.c, src/inspect.c,
src/memory.c, src/menu.c, src/parse.c, src/program.c,
src/register.c, src/scope.c, src/stack.c, src/thread.c,
src/tooltip.c, src/tooltip.h, src/views.c:
Explicitly initialize all sensitive global and static
variables, since reloading the plugin will not do that.
* src/store/scptreestore.c:
Fixed indentation.
* docs/scope.html, src/scope.c:
Increased version to 0.91.2.


2013-07-11 Dimitar Zhekov <dimitar.zhekov@gmail.com>

* src/scope.c:
Expand Down
5 changes: 5 additions & 0 deletions scope/NEWS
@@ -1,3 +1,8 @@
Scope 0.91.2 (2013-07-25)

* Fixed various errors on plugin unload-and-reload.


Scope 0.91.1 (2013-07-11)

* (Un)Block toolbar Toggle Breakpoint when saving a document or
Expand Down
3 changes: 3 additions & 0 deletions scope/NOTES
@@ -1,3 +1,6 @@
reloading a resident geany plugin module does not reinitialize any global
and static variables, so the sensitive ones must be initialized explicitly

register modified is 07 since changing a register ($dh, $mm1.uint64) may
change another ($dx, $st1), and there is some chance of watches/inspects
containing a register
Expand Down
2 changes: 1 addition & 1 deletion scope/docs/scope.html
Expand Up @@ -738,7 +738,7 @@ <h3><a name="legal_info">Legal information</a></h3>

<b><a name="copyright">Copyright</a></b>

<p>Scope 0.91.1, Copyright (C) 2013 Dimitar Toshkov Zhekov</p>
<p>Scope 0.91.2, Copyright (C) 2013 Dimitar Toshkov Zhekov</p>

<p>The menu and toolbar icons are from <a href="http://netbeans.org">Netbeans</a>, except for
BreakPoint.</p>
Expand Down
4 changes: 3 additions & 1 deletion scope/src/break.c
Expand Up @@ -676,7 +676,7 @@ void on_break_list(GArray *nodes)
}
}

gint break_async = -1;
gint break_async;

void on_break_stopped(GArray *nodes)
{
Expand Down Expand Up @@ -1299,6 +1299,8 @@ void break_init(void)
GtkWidget *menu;
guint i;

break_async = -1;

tree = view_connect("break_view", &store, &selection, break_cells, "break_window", NULL);
gtk_tree_view_column_set_cell_data_func(get_column("break_type_column"),
GTK_CELL_RENDERER(get_object("break_type")), break_type_set_data_func, NULL, NULL);
Expand Down
34 changes: 23 additions & 11 deletions scope/src/conterm.c
Expand Up @@ -28,6 +28,7 @@

#define NFD 5
#define DS_COPY (DS_BASICS | DS_EXTRA_1)
static int last_console_fd;

#ifdef G_OS_UNIX
#if (defined(__unix__) || defined(unix)) && !defined(USG)
Expand Down Expand Up @@ -167,23 +168,22 @@ void on_vte_realize(GtkWidget *widget, G_GNUC_UNUSED gpointer gdata)
#endif
}

static VteTerminal *debug_console = NULL; /* non-NULL == vte console */
static VteTerminal *debug_console; /* non-NULL == vte console */

static void console_output(int fd, const char *text, gint length)
{
static const char fd_colors[NFD] = { '6', '7', '1', '7', '5' };
static char setaf[5] = { '\033', '[', '3', '?', 'm' };
static int last_fd = -1;
gint i;

if (last_fd == 3 && fd != 0)
if (last_console_fd == 3 && fd != 0)
vte_terminal_feed(debug_console, "\r\n", 2);

if (fd != last_fd)
if (fd != last_console_fd)
{
setaf[3] = fd_colors[fd];
vte_terminal_feed(debug_console, setaf, sizeof setaf);
last_fd = fd;
last_console_fd = fd;
}

if (length == -1)
Expand Down Expand Up @@ -216,19 +216,21 @@ static GtkTextBuffer *context;
static GtkTextTag *fd_tags[NFD];
#define DC_LIMIT 32768 /* approx */
#define DC_DELTA 6144
static guint dc_chars = 0;
static guint dc_chars;

void context_output(int fd, const char *text, gint length)
{
static int last_fd = -1;
GtkTextIter end;
gchar *utf8;

gtk_text_buffer_get_end_iter(context, &end);

if (last_fd == 3 && fd != 0)
if (last_console_fd == 3 && fd != 0)
gtk_text_buffer_insert(context, &end, "\n", 1);

if (fd != last_console_fd)
last_console_fd = fd;

if (length == -1)
length = strlen(text);

Expand Down Expand Up @@ -379,18 +381,23 @@ static guint console_menu_extra_state(void)
static MenuInfo console_menu_info = { console_menu_items, console_menu_extra_state, 0 };

#ifdef G_OS_UNIX
static int pty_slave = -1;
char *slave_pty_name = NULL;
static int pty_slave;
char *slave_pty_name;
#endif

void conterm_init(void)
{
GtkWidget *console;

#ifdef G_OS_UNIX
gchar *error = NULL;
int pty_master;
char *pty_name;
#endif

last_console_fd = -1;
#ifdef G_OS_UNIX
pty_slave = -1;
slave_pty_name = NULL;

program_window = get_widget("program_window");
console = vte_terminal_new();
Expand Down Expand Up @@ -488,6 +495,11 @@ void conterm_init(void)
"#C0C0C0", "#C000C0" };
guint i;

#ifdef G_OS_UNIX
debug_console = NULL;
#endif
dc_chars = 0;

console = get_widget("debug_context");
gtk_widget_modify_base(console, GTK_STATE_NORMAL, &pref_vte_colour_back);
gtk_widget_modify_cursor(console, &pref_vte_colour_fore, &pref_vte_colour_back);
Expand Down
9 changes: 6 additions & 3 deletions scope/src/debug.c
Expand Up @@ -78,7 +78,7 @@ typedef enum _GdbState
KILLING
} GdbState;

static GdbState gdb_state = INACTIVE;
static GdbState gdb_state;
static GSource *gdb_source;
static GPid gdb_pid;

Expand Down Expand Up @@ -266,7 +266,7 @@ static gboolean source_check(G_GNUC_UNUSED GSource *source)
}
#endif /* G_OS_UNIX */

static guint source_id = 0;
static guint source_id;

static gboolean source_dispatch(G_GNUC_UNUSED GSource *source,
G_GNUC_UNUSED GSourceFunc callback, G_GNUC_UNUSED gpointer gdata)
Expand Down Expand Up @@ -325,7 +325,7 @@ static gboolean source_dispatch(G_GNUC_UNUSED GSource *source,
}

reading_pos = received->str;
result = waitpid(gdb_pid, &status, WNOHANG);
result = waitpid(gdb_pid, &status, WNOHANG);

if (result == 0)
{
Expand Down Expand Up @@ -748,6 +748,9 @@ char *debug_send_evaluate(char token, gint scid, const gchar *expr)

void debug_init(void)
{
gdb_state = INACTIVE;
source_id = 0;

commands = g_string_sized_new(0x3FFF);
received = g_string_sized_new(pref_gdb_buffer_length);
MAXLEN = received->allocated_len - 1;
Expand Down
14 changes: 9 additions & 5 deletions scope/src/inspect.c
Expand Up @@ -163,7 +163,7 @@ static void on_jump_to_menu_item_activate(GtkMenuItem *menuitem, G_GNUC_UNUSED g

static GtkWidget *jump_to_item;
static GtkContainer *jump_to_menu;
static gchar *jump_to_expr = NULL;
static gchar *jump_to_expr;

static void on_inspect_row_inserted(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter,
G_GNUC_UNUSED gpointer gdata)
Expand Down Expand Up @@ -480,7 +480,7 @@ static void inspect_node_change(const ParseNode *node, G_GNUC_UNUSED gpointer gd
}
}

static gboolean query_all_inspects = FALSE;
static gboolean query_all_inspects;

void on_inspect_changelist(GArray *nodes)
{
Expand Down Expand Up @@ -681,10 +681,10 @@ static const TreeCell inspect_cells[] =
};

static GObject *inspect_display;
static gboolean last_state_active;

void inspects_update_state(DebugState state)
{
static gboolean last_active = FALSE;
gboolean active = state != DS_INACTIVE;
GtkTreeIter iter;

Expand All @@ -701,11 +701,11 @@ void inspects_update_state(DebugState state)
g_object_set(inspect_display, "editable", var1 && !numchild, NULL);
}

if (active != last_active)
if (active != last_state_active)
{
gtk_widget_set_sensitive(jump_to_item, active &&
scp_tree_store_get_iter_first(store, &iter));
last_active = active;
last_state_active = active;
}
}

Expand Down Expand Up @@ -1126,6 +1126,10 @@ void inspect_init(void)
{
GtkWidget *menu;

jump_to_expr = NULL;
query_all_inspects = FALSE;
last_state_active = FALSE;

jump_to_item = get_widget("inspect_jump_to_item");
jump_to_menu = GTK_CONTAINER(get_widget("inspect_jump_to_menu"));
apply_item = menu_item_find(inspect_menu_items, "inspect_apply");
Expand Down
7 changes: 5 additions & 2 deletions scope/src/memory.c
Expand Up @@ -117,7 +117,7 @@ static char *addr_format;

static gint back_bytes_per_line;
static gint bytes_per_line;
static gint bytes_per_group = 1;
static gint bytes_per_group;

static void memory_configure(void)
{
Expand All @@ -133,7 +133,7 @@ static void memory_configure(void)
}

static guint64 memory_start;
static guint memory_count = 0;
static guint memory_count;
#define MAX_BYTES (128 * MAX_BYTES_PER_LINE) /* +1 incomplete line */

static void write_block(guint64 start, const char *contents, guint count)
Expand Down Expand Up @@ -382,6 +382,9 @@ void memory_init(void)
GtkWidget *tree = GTK_WIDGET(view_connect("memory_view", &store, &selection,
memory_cells, "memory_window", NULL));

bytes_per_group = 1;
memory_count = 0;

memory_font = *pref_memory_font ? pref_memory_font : pref_vte_font;
ui_widget_modify_font_from_string(tree, memory_font);
g_signal_connect(get_object("memory_bytes"), "editing-started",
Expand Down
10 changes: 7 additions & 3 deletions scope/src/menu.c
Expand Up @@ -51,7 +51,7 @@ void menu_item_execute(const MenuInfo *menu_info, const MenuItem *menu_item, gbo
plugin_beep();
}

static gboolean block_execute = FALSE;
static gboolean block_execute;

void menu_item_set_active(const MenuItem *menu_item, gboolean active)
{
Expand Down Expand Up @@ -109,7 +109,7 @@ static void on_menu_item_activate(GtkMenuItem *menuitem, MenuInfo *menu_info)
}
}

static MenuInfo *active_menu = NULL;
static MenuInfo *active_menu;

static void update_active_menu(guint state)
{
Expand Down Expand Up @@ -404,7 +404,7 @@ void on_menu_update_boolean(const MenuItem *menu_item)
*(gboolean *) menu_item->gdata = gtk_check_menu_item_get_active(item);
}

static char *input = NULL;
static char *input;
static gint eval_mr_mode;
static gint scid_gen = 0;

Expand Down Expand Up @@ -519,6 +519,10 @@ void menu_init(void)
GList *children = gtk_container_get_children(GTK_CONTAINER(shell));
GtkWidget *search2 = find_widget(shell, "search2");

block_execute = FALSE;
active_menu = NULL;
input = NULL;

popup_item = get_widget("popup_item");
menu_connect("popup_menu", &popup_menu_info, NULL);
g_signal_connect(get_widget("popup_evaluate"), "button-release-event",
Expand Down
7 changes: 5 additions & 2 deletions scope/src/parse.c
Expand Up @@ -439,8 +439,8 @@ gchar *parse_get_error(GArray *nodes)

#define MAXLEN 0x7FF
static GString *errors;
static guint errors_id = 0;
static guint error_count = 0;
static guint errors_id;
static guint error_count;

static gboolean errors_show(G_GNUC_UNUSED gpointer gdata)
{
Expand Down Expand Up @@ -620,6 +620,9 @@ void parse_save(GKeyFile *config)

void parse_init(void)
{
errors_id = 0;
error_count = 0;

errors = g_string_sized_new(MAXLEN);
parse_modes = SCP_TREE_STORE(get_object("parse_mode_store"));
scp_tree_store_set_sort_column_id(parse_modes, MODE_NAME, GTK_SORT_ASCENDING);
Expand Down
3 changes: 2 additions & 1 deletion scope/src/program.c
Expand Up @@ -307,7 +307,7 @@ static const gchar *LONG_MR_FORMAT[2];

#define build_check_execute() (build_get_execute(GEANY_BC_COMMAND) || \
build_get_execute(GEANY_BC_WORKING_DIR))
static gboolean last_state_inactive = TRUE;
static gboolean last_state_inactive;

void program_update_state(DebugState state)
{
Expand Down Expand Up @@ -442,6 +442,7 @@ void program_init(void)
extern gboolean thread_select_on_exited;
extern gboolean thread_select_follow;

last_state_inactive = TRUE;
program_dialog = dialog_connect("program_dialog");
program_page_vbox = get_widget("program_page_vbox");

Expand Down
7 changes: 5 additions & 2 deletions scope/src/register.c
Expand Up @@ -70,7 +70,7 @@ static void register_node_update(const ParseNode *node, GString *commands[])
}
}

static gboolean query_all_registers = TRUE;
static gboolean query_all_registers;

static void registers_send_update(GArray *nodes, char token)
{
Expand Down Expand Up @@ -330,7 +330,7 @@ gboolean registers_update(void)
return TRUE;
}

static char *last_gdb_executable = NULL;
static char *last_gdb_executable;

void registers_query_names(void)
{
Expand Down Expand Up @@ -527,6 +527,9 @@ static void on_register_selection_changed(G_GNUC_UNUSED GtkTreeSelection *select

void register_init(void)
{
query_all_registers = TRUE;
last_gdb_executable = NULL;

tree = GTK_WIDGET(view_connect("register_view", &store, &selection, register_cells,
"register_window", &register_display));
gtk_widget_set_has_tooltip(tree, TRUE);
Expand Down

0 comments on commit 015163d

Please sign in to comment.