Branch: refs/heads/master Author: Dimitar Zhekov dimitar.zhekov@gmail.com Committer: Dimitar Zhekov dimitar.zhekov@gmail.com Date: Sun, 20 Jan 2013 19:06:58 UTC Commit: d63ea124412de54da2502670179e9338a8d25c6c https://github.com/geany/geany-plugins/commit/d63ea124412de54da2502670179e93...
Log Message: ----------- scope - memory leaks and other fixes, tips about Memory
Modified Paths: -------------- scope/ChangeLog scope/NOTES scope/docs/scope.html scope/src/break.c scope/src/debug.c scope/src/gtk216.c scope/src/inspect.c scope/src/local.c scope/src/memory.c scope/src/menu.c scope/src/scope.c scope/src/stack.c scope/src/stack.h scope/src/thread.c scope/src/thread.h scope/src/utils.c scope/src/utils.h scope/src/views.c scope/src/views.h scope/src/watch.c
Modified: scope/ChangeLog 36 files changed, 28 insertions(+), 8 deletions(-) =================================================================== @@ -1,3 +1,30 @@ +2013-01-20 Dimitar Zhekov dimitar.zhekov@gmail.com + + * src/debug.c: + Reduced dependency of win32 waitpid()/kill() emulation on glib. + * src/thread.c: + Change frame id to 0 or none immediately after thread change. + * src/stack.c: + Select frame 0 instead of the first available if the current frame + is no longer valid. + * src/local.c, src/views.c, src/views.h, src/watch.c: + Skip stack update if frame 0 for watches only. + * src/stack.c: + Select and focus only if the current frame is not valid any more. + * docs/scope.html: + Added tips about Memory. + * src/memory.c: + Distinguish between memory Clear and auto clear. + Fixed menu extra state bug. + * src/views.c: + Mark memory as auto clear. + * src/break.c, src/inspect.c, src/local.c, src/menu.c, src/stack.c, + src/thread.c, src/views.c, src/utils.c, src/watch.c: + Free string values returned by gtk_tree_model_get(). + * docs/scope.html, src/scope.c: + Increased version to 0.83. + + 2013-01-15 Dimitar Zhekov dimitar.zhekov@gmail.com
* data/scope.glade, docs/codes.html, docs/scope.html, src/common.h, @@ -43,23 +70,16 @@
* src/debug.c, src/scope.c: Ask user whether to terminate debugging on build actions. - * src/debug.c: Ignore "Auto run/exit" on Terminate if neither an executable nor a load script is specified. - - -2013-01-02 Dimitar Zhekov dimitar.zhekov@gmail.com - * docs/codes.html, src/inspect.c, src/inspect.h, src/local.c, src/local.h, src/menu.c, src/menu.h, src/parse.c, src/views.c, src/views.h, src/watch.c, src/watch.h: Unified/simplified all "modified" tokens. The original version was an overkill, and did not update all possible value references. - * src/thread.c: Small "modified" tokens unification related changes. - * docs/scope.html, src/scope.c: Increased version to 0.80.
@@ -140,7 +160,7 @@ * src/common.h, src/menu.h: Fixed forward declarations (though my gcc accepts them). * src/menu.c, src/tooltip.c, src/views.c, src/views.h: - Clear scid_gen on program exit. No real risk of overflow, + Clear scid_gen on program exit. No real risk of overflow, but smaller values look better in Debug Console. * src/menu.c: Position cursor in modify dialog after " = ".
Modified: scope/NOTES 4 files changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -1,3 +1,7 @@ +when switching to stack...memory and update is not possible, the subpage +contents will be kept if an update command for this page was sent on the +last thread stop/changed; otherwise it'll be cleared + "^done,value="", '7' matches 07-var-assign, handled later as "^done", '7'
the only way to fix unnecessary inspect drop target expansion is to block
Modified: scope/docs/scope.html 19 files changed, 18 insertions(+), 1 deletions(-) =================================================================== @@ -47,6 +47,7 @@ <li><a href="#stack">Stack</a></li> <li><a href="#local">Locals</a></li> <li><a href="#watch">Watches</a></li> + <li><a href="#memory">Memory</a></li> <li><a href="#local_watch">Locals/Watches</a></li> <li><a href="#console">Debug Console</a></li> </ul></li> @@ -425,6 +426,19 @@ <p><em>Show .names</em> - display member names. Shift+Click resets it to the value specified in <em>Setup Program</em>.</p>
+<p><b><a name="memory">Memory</a></b></p> + +<p><em>Group by</em> is for visual convinience only and ignores endian.</p> + +<p>Groups are not wrapped, so with <em>Group by</em> > 1, less than +<em>memory_line_bytes</em> may be displayed.</p> + +<p>A maximum of 16K may be displayed (128 lines * 128 bytes); <em>gdb_buffer_length</em> also +limits the size.</p> + +<p><em>Memory</em> empty but <em>Clear</em> available means that the subpage can not be +updated ATM; if you explicitly <em>Clear</em> it, no further updates will take place.</p> + <p><b><a name="console">Debug Console</a></b></p>
<div><table> @@ -537,6 +551,9 @@ <p><em>pref_tooltips_length</em> - maximum length of a tooltip message, 0 = unlimited. Default = 2048.</p>
+<p><em>memory_line_bytes</em></p> - maximum bytes per <em>Memory</em> line</p>. + + <p>[terminal] (*nix only)</p>
<p><em>width</em>, <em>height</em> - VTE widget (not terminal window) size</p> @@ -686,7 +703,7 @@
<b><a name="copyright">Copyright</a></b>
-<p>Scope 0.82, Copyright (C) 2013 Dimitar Toshkov Zhekov</p> +<p>Scope 0.83, 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>
Modified: scope/src/break.c 111 files changed, 76 insertions(+), 35 deletions(-) =================================================================== @@ -50,7 +50,7 @@ enum static gint break_id_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, G_GNUC_UNUSED gpointer gdata) { - const char *s1, *s2; + char *s1, *s2; gint result;
gtk_tree_model_get(model, a, BREAK_ID, &s1, -1); @@ -67,6 +67,8 @@ static gint break_id_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b result = atoi(p1 + (*p1 == '.')) - atoi(p2 + (*p2 == '.')); }
+ g_free(s1); + g_free(s2); return result; }
@@ -136,13 +138,14 @@ static void break_type_set_data_func(G_GNUC_UNUSED GtkTreeViewColumn *column,
static void break_mark(GtkTreeIter *iter, gboolean mark) { - const char *file; + char *file; gint line; gboolean enabled;
gtk_tree_model_get(model, iter, BREAK_FILE, &file, BREAK_LINE, &line, BREAK_ENABLED, &enabled, -1); utils_mark(file, line, mark, MARKER_BREAKPT + enabled); + g_free(file); }
static void break_enable(GtkTreeIter *iter, gboolean enable) @@ -157,7 +160,7 @@ static void on_break_enabled_toggled(G_GNUC_UNUSED GtkCellRendererToggle *render { GtkTreeIter iter; DebugState state = debug_state(); - const char *id; + char *id; gint scid; gboolean enabled;
@@ -177,6 +180,8 @@ static void on_break_enabled_toggled(G_GNUC_UNUSED GtkCellRendererToggle *render } else plugin_beep(); + + g_free(id); }
#define EDITCOLS 3 @@ -193,7 +198,7 @@ static void on_break_column_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, gint index = GPOINTER_TO_INT(gdata) - 1; const gchar *set_text = validate_column(new_text, index > 0); GtkTreeIter iter; - const char *id; + char *id; char type;
gtk_tree_model_get_iter_from_string(model, &iter, path_str); @@ -211,6 +216,8 @@ static void on_break_column_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, gtk_list_store_set(store, &iter, index + BREAK_IGNORE, set_text, -1); else plugin_beep(); + + g_free(id); }
static void on_break_ignore_editing_started(G_GNUC_UNUSED GtkCellRenderer *cell, @@ -273,7 +280,7 @@ static void append_script_command(const ParseNode *node, GString *string)
static void break_iter_applied(GtkTreeIter *iter, const char *id) { - const gchar *columns[EDITCOLS]; + gchar *columns[EDITCOLS]; gboolean enabled; char type; gint index; @@ -284,7 +291,11 @@ static void break_iter_applied(GtkTreeIter *iter, const char *id) if (strchr(BP_BORTS, type)) { if (strchr(BP_BREAKS, type)) + { + g_free(columns[0]); columns[0] = NULL; + } + g_free(columns[1]); columns[1] = NULL; } else if (!enabled) @@ -300,6 +311,7 @@ static void break_iter_applied(GtkTreeIter *iter, const char *id) locale); g_free(locale); } + g_free(columns[index]); } }
@@ -497,9 +509,9 @@ static void break_apply(GtkTreeIter *iter, gboolean thread) GString *command = g_string_sized_new(0x1FF); gint scid; char type; - const char *ignore, *location; + char *ignore, *location; gboolean enabled, pending, temporary; - const gchar *cond; + gchar *cond; gboolean borts;
gtk_tree_model_get(model, iter, BREAK_SCID, &scid, BREAK_TYPE, &type, BREAK_ENABLED, @@ -547,6 +559,9 @@ static void break_apply(GtkTreeIter *iter, gboolean thread) g_string_append_printf(command, " %s", location); debug_send_command(F, command->str); g_string_free(command, TRUE); + g_free(ignore); + g_free(location); + g_free(cond); }
static void break_clear(GtkTreeIter *iter) @@ -573,7 +588,7 @@ static gboolean break_remove_all(const char *pref, gboolean force)
while (valid) { - const char *id; + char *id; gboolean discard;
gtk_tree_model_get(model, &iter, BREAK_ID, &id, BREAK_DISCARD, &discard, -1); @@ -585,12 +600,14 @@ static gboolean break_remove_all(const char *pref, gboolean force) if (discard || force) { valid = break_remove(&iter); + g_free(id); continue; }
break_clear(&iter); }
+ g_free(id); valid = gtk_tree_model_iter_next(model, &iter); }
@@ -641,21 +658,23 @@ static void breaks_missing(void)
while (valid) { - const char *id; + char *id; gboolean discard, missing;
gtk_tree_model_get(model, &iter, BREAK_ID, &id, BREAK_DISCARD, &discard, BREAK_MISSING, &missing, -1); + g_free(id);
if (id && missing) { if (discard) { valid = break_remove(&iter); + g_free(id); continue; } - else - break_clear(&iter); + + break_clear(&iter); }
valid = gtk_tree_model_iter_next(model, &iter); @@ -739,7 +758,7 @@ void on_break_features(GArray *nodes)
static void break_delete(GtkTreeIter *iter) { - const char *id; + char *id;
gtk_tree_model_get(model, iter, BREAK_ID, &id, -1);
@@ -747,11 +766,13 @@ static void break_delete(GtkTreeIter *iter) break_remove(iter); else debug_send_format(N, "023%s-break-delete %s", id, id); + + g_free(id); }
static void break_iter_mark(GtkTreeIter *iter, GeanyDocument *doc) { - const char *file; + char *file; gint line; gboolean enabled;
@@ -760,6 +781,7 @@ static void break_iter_mark(GtkTreeIter *iter, GeanyDocument *doc)
if (line && !utils_filenamecmp(file, doc->real_path)) sci_set_marker_at_line(doc->editor->sci, line - 1, MARKER_BREAKPT + enabled); + g_free(file); }
void breaks_mark(GeanyDocument *doc) @@ -843,10 +865,10 @@ void breaks_delta(ScintillaObject *sci, const char *real_path, gint start, gint
while (valid) { - const char *file; + char *file; gint line; gboolean enabled; - const char *location; + char *location;
gtk_tree_model_get(model, &iter, BREAK_FILE, &file, BREAK_LINE, &line, BREAK_ENABLED, &enabled, BREAK_LOCATION, &location, -1); @@ -872,21 +894,26 @@ void breaks_delta(ScintillaObject *sci, const char *real_path, gint start, gint { sci_delete_marker_at_line(sci, start, MARKER_BREAKPT + enabled); valid = gtk_list_store_remove(store, &iter); + g_free(file); + g_free(location); continue; } }
+ g_free(file); + g_free(location); valid = gtk_tree_model_iter_next(model, &iter); } }
static void break_iter_check(GtkTreeIter *iter, guint *active) { - const char *id; + char *id; gboolean enabled;
gtk_tree_model_get(model, iter, BREAK_ID, &id, BREAK_ENABLED, &enabled, -1); *active += enabled && id; + g_free(id); }
guint breaks_active(void) @@ -902,11 +929,11 @@ void on_break_toggle(G_GNUC_UNUSED const MenuItem *menu_item) gint doc_line = utils_current_line(doc); GtkTreeIter iter, iter1; gboolean valid = gtk_tree_model_get_iter_first(model, &iter); - const char *found = NULL; + gint found = 0;
while (valid) { - const char *id, *file; + char *id, *file; gint line;
gtk_tree_model_get(model, &iter, BREAK_ID, &id, BREAK_FILE, &file, BREAK_LINE, @@ -914,19 +941,23 @@ void on_break_toggle(G_GNUC_UNUSED const MenuItem *menu_item)
if (line == doc_line && !utils_filenamecmp(file, doc->real_path)) { - if (found && atoi(found) != utils_atoi0(id)) + if (found && found != utils_atoi0(id)) { dialogs_show_msgbox(GTK_MESSAGE_INFO, _("There are two or more breakpoints at %s:%d.\n" "Use the breakpoint list to remove the exact one."), doc->file_name, doc_line); + g_free(id); + g_free(file); return; }
- found = id ? id : "-1"; + found = id ? atoi(id) : -1; iter1 = iter; }
+ g_free(id); + g_free(file); valid = gtk_tree_model_iter_next(model, &iter); }
@@ -1030,22 +1061,26 @@ void breaks_load(GKeyFile *config)
static gboolean break_save(GKeyFile *config, const char *section, GtkTreeIter *iter) { - guint i; - gint line; - char type; - gboolean enabled, pending, discard, run_apply, temporary; - const char *strings[STRING_COUNT]; + gboolean discard;
- gtk_tree_model_get(model, iter, BREAK_FILE, &strings[STRING_FILE], BREAK_LINE, &line, - BREAK_TYPE, &type, BREAK_ENABLED, &enabled, BREAK_DISPLAY, - &strings[STRING_DISPLAY], BREAK_FUNC, &strings[STRING_FUNC], BREAK_IGNORE, - &strings[STRING_IGNORE], BREAK_COND, &strings[STRING_COND], BREAK_SCRIPT, - &strings[STRING_SCRIPT], BREAK_PENDING, &pending, BREAK_DISCARD, &discard, - BREAK_LOCATION, &strings[STRING_LOCATION], BREAK_RUN_APPLY, &run_apply, - BREAK_TEMPORARY, &temporary, -1); + gtk_tree_model_get(model, iter, BREAK_DISCARD, &discard, -1);
if (!discard) { + guint i; + gint line; + char type; + gboolean enabled, pending, run_apply, temporary; + char *strings[STRING_COUNT]; + + gtk_tree_model_get(model, iter, BREAK_FILE, &strings[STRING_FILE], BREAK_LINE, + &line, BREAK_TYPE, &type, BREAK_ENABLED, &enabled, BREAK_DISPLAY, + &strings[STRING_DISPLAY], BREAK_FUNC, &strings[STRING_FUNC], BREAK_IGNORE, + &strings[STRING_IGNORE], BREAK_COND, &strings[STRING_COND], BREAK_SCRIPT, + &strings[STRING_SCRIPT], BREAK_PENDING, &pending, BREAK_LOCATION, + &strings[STRING_LOCATION], BREAK_RUN_APPLY, &run_apply, BREAK_TEMPORARY, + &temporary, -1); + if (line) g_key_file_set_integer(config, section, "line", line); else @@ -1059,7 +1094,7 @@ static gboolean break_save(GKeyFile *config, const char *section, GtkTreeIter *i for (i = 0; i < STRING_COUNT; i++) { if (strings[i]) - g_key_file_set_string(config, section, string_names[i], strings[i]); + utils_key_file_set_string(config, section, string_names[i], strings[i]); else g_key_file_remove_key(config, section, string_names[i], NULL); } @@ -1089,7 +1124,7 @@ static void on_break_selection_changed(GtkTreeSelection *selection,
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *id; + char *id; gboolean editable; gint index;
@@ -1097,6 +1132,7 @@ static void on_break_selection_changed(GtkTreeSelection *selection, editable = !id || !strchr(id, '.'); for (index = 0; index < EDITCOLS; index++) g_object_set(block_cells[index], "editable", editable, NULL); + g_free(id); } }
@@ -1124,13 +1160,16 @@ static gboolean on_break_query_tooltip(G_GNUC_UNUSED GtkWidget *widget, gint x, if (line) g_string_append_printf(text, ":%d", line); has_tip = TRUE; + g_free(file); } + if (func) { if (has_tip) g_string_append(text, ", "); g_string_append(text, func); has_tip = TRUE; + g_free(func); }
gtk_tooltip_set_text(tooltip, text->str); @@ -1255,9 +1294,11 @@ static guint break_menu_extra_state(void)
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *id, *file; + char *id, *file;
gtk_tree_model_get(model, &iter, BREAK_ID, &id, BREAK_FILE, &file, -1); + g_free(id); + g_free(file);
return (!id << DS_INDEX_1) | ((file != NULL) << DS_INDEX_2) | ((!id || !strchr(id, '.')) << DS_INDEX_3);
Modified: scope/src/debug.c 7 files changed, 3 insertions(+), 4 deletions(-) =================================================================== @@ -31,9 +31,7 @@ #else /* G_OS_UNIX */ #include <windows.h>
-#define WNOHANG 0 - -static int waitpid(GPid pid, int *stat_loc, G_GNUC_UNUSED int options) +static int waitpid(HANDLE pid, int *stat_loc) { DWORD status;
@@ -49,10 +47,11 @@ static int waitpid(GPid pid, int *stat_loc, G_GNUC_UNUSED int options)
return -1; } +#define waitpid(pid, stat_loc, options) waitpid((pid), (stat_loc))
#define SIGKILL 9
-static int kill(GPid pid, int sig) +static int kill(HANDLE pid, int sig) { return TerminateProcess(pid, sig) ? 0 : -1; }
Modified: scope/src/gtk216.c 6 files changed, 3 insertions(+), 3 deletions(-) =================================================================== @@ -31,10 +31,10 @@
static ArraySize *find_array_size(GArray *array) { - guint i; - gchar *data = array_sizes->data; + gchar *end = array_sizes->data + sizeof(ArraySize) * array>len; + gchar *data;
- for (i = 0; i < array_sizes->len; i++, data += sizeof(ArraySize)) + for (data = array_sizes->data; data < end; data += sizeof(ArraySize)) if (*(GArray **) data == array) return (ArraySize *) data;
Modified: scope/src/inspect.c 110 files changed, 72 insertions(+), 38 deletions(-) =================================================================== @@ -92,13 +92,16 @@ static gboolean inspect_find_recursive(GtkTreeIter *iter, gint i, const char *ke } else { - const char *var1; + char *var1; size_t len; + gboolean match;
gtk_tree_model_get(model, iter, INSPECT_VAR1, &var1, -1); len = var1 ? strlen(var1) : 0; + match = var1 && !strncmp(key, var1, len); + g_free(var1);
- if (var1 && !strncmp(key, var1, len)) + if (match) { if (key[len] == '\0') return TRUE; @@ -150,9 +153,8 @@ static gint inspect_get_scid(GtkTreeIter *iter)
static void inspect_expand(GtkTreeIter *iter) { - const char *var1; + char *var1, *s; gint scid, start, count, numchild; - gchar *s;
scid = inspect_get_scid(iter); gtk_tree_model_get(model, iter, INSPECT_VAR1, &var1, INSPECT_START, &start, @@ -160,6 +162,7 @@ static void inspect_expand(GtkTreeIter *iter) s = g_strdup_printf("%d", start); debug_send_format(N, "07%c%d%d-var-list-children 1 %s %d %d", '0' + (int) strlen(s) - 1, start, scid, var1, start, count ? start + count : numchild); + g_free(var1); g_free(s); }
@@ -174,7 +177,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 const gchar *jump_to_expr; +static gchar *jump_to_expr = NULL;
static void on_inspect_row_inserted(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, G_GNUC_UNUSED gpointer gdata) @@ -184,6 +187,7 @@ static void on_inspect_row_inserted(GtkTreeModel *model, GtkTreePath *path, GtkT GtkWidget *item; const gint *index = gtk_tree_path_get_indices(path);
+ g_free(jump_to_expr); gtk_tree_model_get(model, iter, INSPECT_EXPR, &jump_to_expr, -1); item = gtk_menu_item_new_with_label(jump_to_expr ? jump_to_expr : ""); gtk_widget_show(item); @@ -343,8 +347,7 @@ void on_inspect_children(GArray *nodes)
if (inspect_find(&iter, FALSE, token + size)) { - gint from, numchild, end; - const char *var1; + gint from; GtkTreePath *path = gtk_tree_model_get_path(model, &iter);
token[size] = '\0'; @@ -355,6 +358,9 @@ void on_inspect_children(GArray *nodes) append_stub(&iter, _("no children in range"), FALSE); else { + gint numchild, end; + char *var1; + if (from) append_ellipsis(&iter, FALSE);
@@ -369,6 +375,7 @@ void on_inspect_children(GArray *nodes) debug_send_format(N, "04-var-set-update-range %s %d %d", var1, from, end); } + g_free(var1);
if (nodes->len ? end < numchild : !from) append_ellipsis(&iter, FALSE); @@ -470,14 +477,16 @@ void on_inspect_changelist(GArray *nodes) static void inspect_apply(GtkTreeIter *iter) { gint scid; - const gchar *expr; - const char *name, *frame; - char *locale; + gchar *expr; + char *name, *frame, *locale;
gtk_tree_model_get(model, iter, INSPECT_EXPR, &expr, INSPECT_SCID, &scid, INSPECT_NAME, &name, INSPECT_FRAME, &frame, -1); locale = utils_get_locale_from_utf8(expr); debug_send_format(F, "07%d-var-create %s %s %s", scid, name, frame, locale); + g_free(expr); + g_free(name); + g_free(frame); g_free(locale); }
@@ -489,9 +498,10 @@ void on_inspect_signal(const char *name) { iff (model_find(model, &iter, INSPECT_NAME, name), "%s: var not found", name) { - const char *var1; + char *var1;
gtk_tree_model_get(model, &iter, INSPECT_VAR1, &var1, -1); + g_free(var1);
iff (!var1, "%s: already applied", name) inspect_apply(&iter); @@ -521,7 +531,7 @@ gboolean inspects_current(void)
static void inspect_iter_apply(GtkTreeIter *iter, G_GNUC_UNUSED gpointer gdata) { - const char *frame; + char *frame; gboolean run_apply;
gtk_tree_model_get(model, iter, INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, @@ -529,6 +539,7 @@ static void inspect_iter_apply(GtkTreeIter *iter, G_GNUC_UNUSED gpointer gdata)
if (run_apply && !isdigit(*frame)) inspect_apply(iter); + g_free(frame); }
void inspects_apply(void) @@ -640,7 +651,7 @@ void inspects_update_state(DebugState state) static gboolean last_active = FALSE; gboolean active = state != DS_INACTIVE; GtkTreeIter iter; - const char *var1 = NULL; + char *var1 = NULL; gint numchild = 0;
if ((state & DS_SENDABLE) && gtk_tree_selection_get_selected(selection, NULL, &iter)) @@ -649,6 +660,7 @@ void inspects_update_state(DebugState state) -1); } g_object_set(inspect_display, "editable", var1 && !numchild, NULL); + g_free(var1);
if (active != last_active) { @@ -707,18 +719,18 @@ void inspects_load(GKeyFile *config) static gboolean inspect_save(GKeyFile *config, const char *section, GtkTreeIter *iter) { gint hb_mode, start, count, format; - const char *name, *frame; - const gchar *expr; + char *name, *frame; + gchar *expr; gboolean run_apply, expand;
gtk_tree_model_get(model, iter, INSPECT_EXPR, &expr, INSPECT_HB_MODE, &hb_mode, INSPECT_NAME, &name, INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, INSPECT_START, &start, INSPECT_COUNT, &count, INSPECT_EXPAND, &expand, INSPECT_FORMAT, &format, -1); - g_key_file_set_string(config, section, "name", name); - g_key_file_set_string(config, section, "expr", expr); + utils_key_file_set_string(config, section, "name", name); + utils_key_file_set_string(config, section, "expr", expr); g_key_file_set_integer(config, section, "hbit", hb_mode); - g_key_file_set_string(config, section, "frame", frame); + utils_key_file_set_string(config, section, "frame", frame); g_key_file_set_boolean(config, section, "run_apply", run_apply); g_key_file_set_integer(config, section, "start", start); g_key_file_set_integer(config, section, "count", count); @@ -740,26 +752,25 @@ static void on_inspect_refresh(G_GNUC_UNUSED const MenuItem *menu_item) static void on_inspect_add(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const gchar *expr = NULL; + gchar *expr = NULL;
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) gtk_tree_model_get(model, &iter, INSPECT_PATH_EXPR, &expr, -1);
inspect_add(expr); + g_free(expr); }
static void on_inspect_edit(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const gchar *expr; - char *name; - const char *frame; + gchar *expr; + char *name, *frame; gboolean run_apply;
gtk_tree_selection_get_selected(selection, NULL, &iter); gtk_tree_model_get(model, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, -1); - name = strdup(name); gtk_tree_store_set(store, &iter, INSPECT_NAME, "-", -1); /* for duplicate name check */
gtk_entry_set_text(inspect_expr, expr); @@ -770,26 +781,32 @@ static void on_inspect_edit(G_GNUC_UNUSED const MenuItem *menu_item)
if (gtk_dialog_run(GTK_DIALOG(inspect_dialog)) == GTK_RESPONSE_ACCEPT) { + g_free(jump_to_expr); jump_to_expr = NULL; inspect_dialog_store(&iter); } else gtk_tree_store_set(store, &iter, INSPECT_NAME, name, -1);
+ g_free(expr); g_free(name); + g_free(frame); }
static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const char *var1; + char *var1; gint scid;
gtk_tree_selection_get_selected(selection, NULL, &iter); gtk_tree_model_get(model, &iter, INSPECT_SCID, &scid, INSPECT_VAR1, &var1, -1);
if (var1) + { debug_send_format(N, "070%d-var-delete %s", scid, var1); + g_free(var1); + } else inspect_apply(&iter); } @@ -802,7 +819,7 @@ static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) static void on_inspect_expand(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const char *name; + char *name; gint start, count; gboolean expand;
@@ -813,6 +830,7 @@ static void on_inspect_expand(G_GNUC_UNUSED const MenuItem *menu_item) gtk_spin_button_set_value(expand_count, count); gtk_toggle_button_set_active(expand_automatic, expand); gtk_widget_set_sensitive(GTK_WIDGET(expand_automatic), name != NULL); + g_free(name);
if (gtk_dialog_run(GTK_DIALOG(expand_dialog)) == GTK_RESPONSE_ACCEPT) { @@ -842,7 +860,7 @@ static void on_inspect_format_update(const MenuItem *menu_item) { GtkTreeIter iter; gint format = GPOINTER_TO_INT(menu_item->gdata); - const char *var1; + char *var1;
gtk_tree_selection_get_selected(selection, NULL, &iter); gtk_tree_model_get(model, &iter, INSPECT_VAR1, &var1, -1); @@ -851,6 +869,7 @@ static void on_inspect_format_update(const MenuItem *menu_item) { debug_send_format(N, "07%d-var-set-format %s %s", inspect_get_scid(&iter), var1, inspect_formats[format]); + g_free(var1); } else gtk_tree_store_set(store, &iter, INSPECT_FORMAT, format, -1); @@ -863,20 +882,21 @@ static void on_inspect_hbit_display(const MenuItem *menu_item)
static void inspect_hbit_update_iter(GtkTreeIter *iter, gint hb_mode) { - const char *value; + char *value; gchar *display;
gtk_tree_model_get(model, iter, INSPECT_VALUE, &value, -1); display = utils_get_display_from_7bit(value, hb_mode); gtk_tree_store_set(store, iter, INSPECT_HB_MODE, hb_mode, value ? INSPECT_DISPLAY : -1, display, -1); + g_free(value); g_free(display); }
static void on_inspect_hbit_update(const MenuItem *menu_item) { GtkTreeIter iter; - const char *expr, *name; + char *expr, *name; gint hb_mode = GPOINTER_TO_INT(menu_item->gdata);
gtk_tree_selection_get_selected(selection, NULL, &iter); @@ -892,18 +912,24 @@ static void on_inspect_hbit_update(const MenuItem *menu_item) inspect_hbit_update_iter(&iter, hb_mode); g_free(reverse); } + + g_free(expr); + g_free(name); }
static void on_inspect_delete(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const char *var1; + char *var1;
gtk_tree_selection_get_selected(selection, NULL, &iter); gtk_tree_model_get(model, &iter, INSPECT_VAR1, &var1, -1);
if (var1) + { debug_send_format(N, "071%d-var-delete %s", inspect_get_scid(&iter), var1); + g_free(var1); + } else gtk_tree_store_remove(store, &iter); } @@ -942,19 +968,20 @@ static void on_inspect_delete(G_GNUC_UNUSED const MenuItem *menu_item) static guint inspect_menu_extra_state(void) { GtkTreeIter iter; - guint state = gtk_tree_selection_get_selected(selection, NULL, &iter) << DS_INDEX_1;
- if (state) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *var1, *name; + char *var1, *name; gint numchild;
gtk_tree_model_get(model, &iter, INSPECT_VAR1, &var1, INSPECT_NAME, &name, INSPECT_NUMCHILD, &numchild, -1); + g_free(var1); + g_free(name);
if (name || var1) { - return state | ((name && !var1) << DS_INDEX_2) | + return (1 << DS_INDEX_1) | ((name && !var1) << DS_INDEX_2) | ((name != NULL) << DS_INDEX_3) | ((numchild != 0) << DS_INDEX_4); } } @@ -968,7 +995,7 @@ static void on_inspect_selection_changed(G_GNUC_UNUSED GtkTreeSelection *selecti G_GNUC_UNUSED gpointer gdata) { GtkTreeIter iter; - const char *name = NULL; + char *name = NULL;
if (gtk_widget_get_visible(inspect_dialog)) gtk_widget_hide(inspect_dialog); @@ -977,20 +1004,22 @@ static void on_inspect_selection_changed(G_GNUC_UNUSED GtkTreeSelection *selecti
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) gtk_tree_model_get(model, &iter, INSPECT_NAME, &name, -1); - gtk_tree_view_set_reorderable(tree, name != NULL);
+ gtk_tree_view_set_reorderable(tree, name != NULL); inspects_update_state(debug_state()); + g_free(name); }
static gboolean inspect_test_expand_row(G_GNUC_UNUSED GtkTreeView *tree_view, GtkTreeIter *iter, G_GNUC_UNUSED GtkTreePath *path, G_GNUC_UNUSED gpointer gdata) { GtkTreeIter child; - const char *var1; + char *var1; gboolean expand;
gtk_tree_model_iter_children(model, &child, iter); gtk_tree_model_get(model, &child, INSPECT_VAR1, &var1, INSPECT_EXPAND, &expand, -1); + g_free(var1);
if (var1 || !expand) return FALSE; @@ -1038,11 +1067,12 @@ gboolean on_inspect_drag_motion(G_GNUC_UNUSED GtkWidget *widget, if (gtk_tree_view_get_dest_row_at_pos(tree, x, y, &path, &pos)) { GtkTreeIter iter; - const char *name; + char *name;
gtk_tree_model_get_iter(model, &iter, path); gtk_tree_path_free(path); gtk_tree_model_get(model, &iter, INSPECT_NAME, &name, -1); + g_free(name);
if (!name || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_AFTER) @@ -1060,7 +1090,7 @@ static void on_inspect_menu_show(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *var1, *path_expr; + char *var1, *path_expr;
gtk_tree_model_get(model, &iter, INSPECT_VAR1, &var1, INSPECT_PATH_EXPR, &path_expr, -1); @@ -1071,6 +1101,9 @@ static void on_inspect_menu_show(G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED debug_send_format(N, "04%d-var-info-path-expression %s", inspect_get_scid(&iter), var1); } + + g_free(var1); + g_free(path_expr); } }
@@ -1137,4 +1170,5 @@ void inspect_finalize(void) gtk_widget_destroy(inspect_page); gtk_widget_destroy(inspect_dialog); gtk_widget_destroy(expand_dialog); + g_free(jump_to_expr); }
Modified: scope/src/local.c 9 files changed, 3 insertions(+), 6 deletions(-) =================================================================== @@ -89,15 +89,11 @@ void on_local_variables(GArray *nodes) if (thread_id && frame_id && len == strlen(thread_id) && !memcmp(++token, thread_id, len) && !strcmp(token + len, frame_id)) { - char *name = NULL; GtkTreeIter iter; LocalData ld = { NULL, stack_entry() };
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) - { gtk_tree_model_get(model, &iter, LOCAL_NAME, &ld.name, -1); - name = g_strdup(name); - }
locals_clear(); array_foreach(parse_lead_array(nodes), (GFunc) local_node_variable, &ld); @@ -118,7 +114,7 @@ static void local_send_update(char token)
gboolean locals_update(void) { - if (view_select_frame()) + if (view_stack_update()) return FALSE;
if (frame_id) @@ -160,11 +156,12 @@ static void on_local_modify(const MenuItem *menu_item) static void on_local_watch(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const char *name; + char *name;
gtk_tree_selection_get_selected(selection, NULL, &iter); gtk_tree_model_get(model, &iter, LOCAL_NAME, &name, -1); watch_add(name); + g_free(name); }
static void on_local_inspect(G_GNUC_UNUSED const MenuItem *menu_item)
Modified: scope/src/memory.c 24 files changed, 14 insertions(+), 10 deletions(-) =================================================================== @@ -41,7 +41,7 @@ static void on_memory_bytes_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, if (*new_text && (debug_state() & DS_SENDABLE)) { GtkTreeIter iter; - const char *addr, *bytes; + char *addr, *bytes; guint i;
gtk_tree_model_get_iter_from_string(model, &iter, path_str); @@ -58,6 +58,9 @@ static void on_memory_bytes_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, utils_strchrepl(new_text, ' ', '\0'); debug_send_format(T, "07-data-write-memory-bytes 0x%s%s", addr, new_text); } + + g_free(addr); + g_free(bytes); } else plugin_blink(); @@ -232,12 +235,10 @@ void on_memory_read_bytes(GArray *nodes) char *addr = NULL;
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) - { gtk_tree_model_get(model, &iter, MEMORY_ADDR, &addr, -1); - addr = strdup(addr); - }
- memory_clear(); + gtk_list_store_clear(store); + memory_count = 0;
if (pref_memory_bytes_per_line != back_bytes_per_line) { @@ -261,7 +262,6 @@ void on_memory_read_bytes(GArray *nodes) void memory_clear(void) { gtk_list_store_clear(store); - memory_count = 0; }
gboolean memory_update(void) @@ -304,8 +304,8 @@ static void on_memory_copy(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeModel *model; GtkTreeIter iter; - const char *addr, *bytes; - const gchar *ascii; + char *addr, *bytes; + gchar *ascii; gchar *string;
gtk_tree_selection_get_selected(selection, &model, &iter); @@ -314,12 +314,16 @@ static void on_memory_copy(G_GNUC_UNUSED const MenuItem *menu_item) string = g_strdup_printf("%s%s%s", addr, bytes, ascii); gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, GDK_SELECTION_CLIPBOARD), string, -1); + g_free(addr); + g_free(bytes); + g_free(ascii); g_free(string); }
static void on_memory_clear(G_GNUC_UNUSED const MenuItem *menu_item) { - memory_clear(); + gtk_list_store_clear(store); + memory_count = 0; }
static void on_memory_group_display(const MenuItem *menu_item) @@ -364,7 +368,7 @@ static void on_memory_group_update(const MenuItem *menu_item) static guint memory_menu_extra_state(void) { return (gtk_tree_selection_get_selected(selection, NULL, NULL) << DS_INDEX_1) | - (memory_count != 0) << DS_INDEX_1; + (memory_count != 0) << DS_INDEX_2; }
static MenuInfo memory_menu_info = { memory_menu_items, memory_menu_extra_state, 0 };
Modified: scope/src/menu.c 23 files changed, 16 insertions(+), 7 deletions(-) =================================================================== @@ -208,7 +208,7 @@ static void menu_mode_update_iter(GtkTreeModel *model, GtkTreeIter *iter, gint n gboolean hbit) { gint hb_mode, mr_mode; - const char *value; + char *value; gchar *display;
gtk_tree_model_get(model, iter, COLUMN_VALUE, &value, COLUMN_HB_MODE, &hb_mode, @@ -222,6 +222,7 @@ static void menu_mode_update_iter(GtkTreeModel *model, GtkTreeIter *iter, gint n display = parse_get_display_from_7bit(value, hb_mode, mr_mode); gtk_list_store_set(GTK_LIST_STORE(model), iter, COLUMN_HB_MODE, hb_mode, COLUMN_MR_MODE, mr_mode, value ? COLUMN_DISPLAY : -1, display, -1); + g_free(value); g_free(display); }
@@ -229,7 +230,7 @@ void menu_mode_update(GtkTreeSelection *selection, gint new_mode, gboolean hbit) { GtkTreeModel *model; GtkTreeIter iter; - const char *name; + char *name;
gtk_tree_selection_get_selected(selection, &model, &iter); gtk_tree_model_get(model, &iter, COLUMN_NAME, &name, -1); @@ -244,6 +245,7 @@ void menu_mode_update(GtkTreeSelection *selection, gint new_mode, gboolean hbit) menu_mode_update_iter(model, &iter, new_mode, TRUE); g_free(reverse); } + g_free(name); }
void menu_mber_display(GtkTreeSelection *selection, const MenuItem *menu_item) @@ -298,8 +300,8 @@ void menu_copy(GtkTreeSelection *selection, const MenuItem *menu_item) { GtkTreeModel *model; GtkTreeIter iter; - const gchar *name, *display; - const char *value; + gchar *name, *display; + char *value; GString *string;
gtk_tree_selection_get_selected(selection, &model, &iter); @@ -312,6 +314,10 @@ void menu_copy(GtkTreeSelection *selection, const MenuItem *menu_item)
gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, GDK_SELECTION_CLIPBOARD), string->str, string->len); + + g_free(name); + g_free(display); + g_free(value); g_string_free(string, TRUE); }
@@ -364,8 +370,8 @@ void menu_modify(GtkTreeSelection *selection, const MenuItem *menu_item) { GtkTreeModel *model; GtkTreeIter iter; - const gchar *name; - const char *value; + gchar *name; + char *value; gint hb_mode;
gtk_tree_selection_get_selected(selection, &model, &iter); @@ -373,17 +379,20 @@ void menu_modify(GtkTreeSelection *selection, const MenuItem *menu_item) &hb_mode, -1); menu_evaluate_modify(name, value, _("Modify"), hb_mode, menu_item ? MR_MODIFY : MR_MODSTR, "07"); + g_free(name); + g_free(value); }
void menu_inspect(GtkTreeSelection *selection) { GtkTreeModel *model; GtkTreeIter iter; - const char *name; + char *name;
gtk_tree_selection_get_selected(selection, &model, &iter); gtk_tree_model_get(model, &iter, COLUMN_NAME, &name, -1); inspect_add(name); + g_free(name); }
void on_menu_display_booleans(const MenuItem *menu_item)
Modified: scope/src/scope.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -32,7 +32,7 @@ PLUGIN_VERSION_CHECK(215)
PLUGIN_SET_TRANSLATABLE_INFO(LOCALEDIR, GETTEXT_PACKAGE, _("Scope Debugger"), - _("Simple GDB front-end."), "0.82" , "Dimitar Toshkov Zhekov dimitar.zhekov@gmail.com") + _("Simple GDB front-end."), "0.83" , "Dimitar Toshkov Zhekov dimitar.zhekov@gmail.com")
/* Keybinding(s) */ enum @@ -602,6 +602,7 @@ void plugin_cleanup(void) thread_finalize(); break_finalize(); memory_finalize(); + stack_finalize(); menu_finalize(); views_finalize(); utils_finalize();
Modified: scope/src/stack.c 66 files changed, 43 insertions(+), 23 deletions(-) =================================================================== @@ -59,12 +59,12 @@ static void stack_node_location(const ParseNode *node, const char *fid) parse_location_free(&loc);
if (!g_strcmp0(id, fid)) - utils_tree_set_cursor(selection, &iter, -1); + gtk_tree_selection_select_iter(selection, &iter); } } }
-const char *frame_id = NULL; +char *frame_id = NULL;
void on_stack_frames(GArray *nodes) { @@ -80,7 +80,7 @@ void on_stack_frames(GArray *nodes) { GtkTreeIter iter;
- if (gtk_tree_model_get_iter_first(model, &iter)) + if (model_find(model, &iter, STACK_ID, "0")) utils_tree_set_cursor(selection, &iter, -1); } } @@ -135,10 +135,11 @@ static void stack_node_arguments(const ParseNode *node, ArgsData *ad) { if (ad->valid) { - const char *fid; + char *fid;
gtk_tree_model_get(model, &ad->iter, STACK_ID, &fid, -1); ad->valid = !strcmp(id, fid); + g_free(fid); }
if (!ad->valid) @@ -223,6 +224,8 @@ static void on_stack_selection_changed(GtkTreeSelection *selection, { GtkTreeIter iter;
+ g_free(frame_id); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) gtk_tree_model_get(model, &iter, STACK_ID, &frame_id, -1); else @@ -271,31 +274,41 @@ static void on_stack_show_address(const MenuItem *menu_item) view_column_set_visible("stack_addr_column", stack_show_address); }
+typedef struct _EntryData +{ + char *func; + gboolean entry; + gint count; +} EntryData; + +static void stack_iter_show_entry(GtkTreeIter *iter, EntryData *ed) +{ + char *func; + + gtk_tree_model_get(model, iter, STACK_FUNC, &func, -1); + + if (func && !strcmp(func, ed->func)) + { + gtk_list_store_set(store, iter, STACK_ENTRY, ed->entry, -1); + ed->count++; + } + g_free(func); +} + static void on_stack_show_entry(const MenuItem *menu_item) { - gboolean entry = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)); + EntryData ed = { NULL, + gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)), 0 }; GtkTreeIter iter; - const char *func; - guint count = 0;
view_dirty(VIEW_LOCALS); gtk_tree_selection_get_selected(selection, NULL, &iter); - gtk_tree_model_get(model, &iter, STACK_FUNC, &func, -1); - parse_mode_update(func, MODE_ENTRY, entry); - gtk_tree_model_get_iter_first(model, &iter); - do - { - const char *func1; + gtk_tree_model_get(model, &iter, STACK_FUNC, &ed.func, -1); + parse_mode_update(ed.func, MODE_ENTRY, ed.entry); + model_foreach(model, (GFunc) stack_iter_show_entry, &ed); + g_free(ed.func);
- gtk_tree_model_get(model, &iter, STACK_FUNC, &func1, -1); - if (!strcmp(func, func1)) - { - gtk_list_store_set(store, &iter, STACK_ENTRY, entry, -1); - count++; - } - } while (gtk_tree_model_iter_next(model, &iter)); - - if (count == 1) + if (ed.count == 1) { debug_send_format(T, "04%s-stack-list-arguments 1 %s %s", thread_id, frame_id, frame_id); @@ -324,9 +337,11 @@ static guint stack_menu_extra_state(void)
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *file, *func; + char *file, *func;
gtk_tree_model_get(model, &iter, STACK_FILE, &file, STACK_FUNC, &func, -1); + g_free(file); + g_free(func); return ((file != NULL) << DS_INDEX_2) | ((func != NULL) << DS_INDEX_3); }
@@ -379,3 +394,8 @@ void stack_init(void) g_signal_connect(get_widget("stack_synchronize"), "button-release-event", G_CALLBACK(on_stack_synchronize_button_release), menu); } + +void stack_finalize(void) +{ + g_free(frame_id); +}
Modified: scope/src/stack.h 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -19,7 +19,7 @@
#ifndef STACK_H
-extern const char *frame_id; +extern char *frame_id;
void on_stack_frames(GArray *nodes); void on_stack_arguments(GArray *nodes); @@ -30,6 +30,7 @@ gboolean stack_update(void);
void stack_init(void); +void stack_finalize(void);
#define STACK_H 1 #endif
Modified: scope/src/thread.c 85 files changed, 60 insertions(+), 25 deletions(-) =================================================================== @@ -140,10 +140,12 @@ enum static gint thread_ident_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer gdata) { - const char *s1, *s2; + char *s1, *s2; + gint result;
gtk_tree_model_get(model, a, GPOINTER_TO_INT(gdata), &s1, -1); gtk_tree_model_get(model, b, GPOINTER_TO_INT(gdata), &s2, -1); + result = g_strcmp0(s1, s2);
if (s1 && s2) { @@ -153,10 +155,12 @@ static gint thread_ident_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIte for (p2 = s2; *p2 && !isdigit(*p2); p2++);
if (p1 - s1 == p2 - s2 && !memcmp(s1, s2, p1 - s1)) - return atoi(p1) - atoi(p2); + result = atoi(p1) - atoi(p2); }
- return g_strcmp0(s1, s2); + g_free(s1); + g_free(s2); + return result; }
static GtkListStore *store; @@ -188,14 +192,14 @@ static void auto_select_thread(void) }
guint thread_count = 0; -const char *thread_id = NULL; +char *thread_id = NULL; ThreadState thread_state = THREAD_BLANK; guint thread_prompt = 0;
-const char *thread_group_id(void) +char *thread_group_id(void) { GtkTreeIter iter; - const char *gid = NULL; + char *gid = NULL;
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) gtk_tree_model_get(model, &iter, THREAD_GROUP_ID, &gid, -1); @@ -205,7 +209,8 @@ const char *thread_group_id(void)
static void thread_iter_unmark(GtkTreeIter *iter, gpointer gdata) { - const char *file, *state; + char *file; + gchar *state; gint line; gboolean stopped;
@@ -216,6 +221,9 @@ static void thread_iter_unmark(GtkTreeIter *iter, gpointer gdata)
if (GPOINTER_TO_INT(gdata) != 2) utils_mark(file, line, FALSE, MARKER_EXECUTE); + + g_free(file); + g_free(state); }
static void thread_iter_running(GtkTreeIter *iter, const char *tid) @@ -228,11 +236,15 @@ static void thread_iter_running(GtkTreeIter *iter, const char *tid)
if (thread_id) { - if (!tid) - gtk_tree_model_get(model, iter, THREAD_ID, &tid, -1); + char *tid1 = g_strdup(tid); + + if (!tid1) + gtk_tree_model_get(model, iter, THREAD_ID, &tid1, -1);
- if (!strcmp(tid, thread_id)) + if (!strcmp(tid1, thread_id)) thread_state = THREAD_RUNNING; + + g_free(tid1); } }
@@ -313,10 +325,12 @@ static void thread_parse_frame(GArray *frame, const char *tid, GtkTreeIter *iter
static void thread_iter_stopped(GtkTreeIter *iter, StopData *sd) { - const char *tid = sd->tid, *state, *addr; + char *tid = g_strdup(sd->tid), *addr; + gchar *state;
gtk_tree_model_get(model, iter, THREAD_STATE, &state, THREAD_ADDR, &addr, tid ? -1 : THREAD_ID, &tid, -1); + if (strcmp(state, STOPPED)) thread_prompt++; gtk_list_store_set(store, iter, THREAD_STATE, STOPPED, -1); @@ -336,6 +350,10 @@ static void thread_iter_stopped(GtkTreeIter *iter, StopData *sd) sd->iter = *iter; sd->found = TRUE; } + + g_free(tid); + g_free(state); + g_free(addr); }
static void thread_node_stopped(const ParseNode *node, StopData *sd) @@ -527,11 +545,12 @@ static void thread_parse(GArray *nodes, const char *tid, gboolean stopped) } else { - const gchar *state; + gchar *state;
gtk_tree_model_get(model, &iter, THREAD_STATE, &state, -1); if (strcmp(state, RUNNING)) thread_iter_running(&iter, tid); + g_free(state); }
thread_parse_extra(nodes, &iter, "target-id", THREAD_TARGET_ID); @@ -582,13 +601,14 @@ void on_thread_frame(GArray *nodes)
static void thread_iter_mark(GtkTreeIter *iter, GeanyDocument *doc) { - const char *file; + char *file; gint line;
gtk_tree_model_get(model, iter, THREAD_FILE, &file, THREAD_LINE, &line, -1);
if (line && !utils_filenamecmp(file, doc->real_path)) sci_set_marker_at_line(doc->editor->sci, line - 1, MARKER_EXECUTE); + g_free(file); }
void threads_mark(GeanyDocument *doc) @@ -613,7 +633,7 @@ void threads_delta(ScintillaObject *sci, const char *real_path, gint start, gint
while (valid) { - const char *file; + char *file; gint line;
gtk_tree_model_get(model, &iter, THREAD_FILE, &file, THREAD_LINE, &line, -1); @@ -621,6 +641,7 @@ void threads_delta(ScintillaObject *sci, const char *real_path, gint start, gint if (--line >= 0 && start <= line && !utils_filenamecmp(file, real_path)) utils_move_mark(sci, line, start, delta, MARKER_EXECUTE);
+ g_free(file); valid = gtk_tree_model_iter_next(model, &iter); } } @@ -647,17 +668,22 @@ static void on_thread_selection_changed(GtkTreeSelection *selection, { GtkTreeIter iter;
+ free(thread_id); + free(frame_id); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const gchar *state; + gchar *state; gint line; - const char *addr; + char *addr;
gtk_tree_model_get(model, &iter, THREAD_ID, &thread_id, THREAD_STATE, &state, THREAD_LINE, &line, THREAD_ADDR, &addr, -1);
if (strcmp(state, STOPPED)) + { thread_state = *state ? THREAD_RUNNING : THREAD_BLANK; + } else if (addr) { if (line) @@ -677,10 +703,14 @@ static void on_thread_selection_changed(GtkTreeSelection *selection, else thread_state = THREAD_QUERY_FRAME; } + + frame_id = strdup("0"); + g_free(state); + g_free(addr); } else { - thread_id = NULL; + thread_id = frame_id = NULL; thread_state = THREAD_BLANK; }
@@ -726,11 +756,12 @@ static void send_signal(int sig)
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *pid; + char *pid;
gtk_tree_model_get(model, &iter, THREAD_PID, &pid, -1); if (kill(atoi(pid), sig) == -1) show_errno("kill(pid)"); + g_free(pid); } else plugin_beep(); @@ -763,7 +794,7 @@ static void on_thread_send_signal(G_GNUC_UNUSED const MenuItem *menu_item) #else /* G_OS_UNIX */ static HANDLE iter_to_handle(GtkTreeIter *iter) { - const char *pid; + char *pid; HANDLE hid;
gtk_tree_model_get(model, iter, THREAD_PID, &pid, -1); @@ -771,6 +802,7 @@ static HANDLE iter_to_handle(GtkTreeIter *iter) if (!hid) show_errno("OpenProcess");
+ g_free(pid); return hid; }
@@ -833,8 +865,6 @@ static void on_thread_show_core(const MenuItem *menu_item) }
#define DS_VIEWABLE (DS_ACTIVE | DS_EXTRA_2) -#define DS_INTRABLE (DS_ACTIVE | DS_EXTRA_3) -#define DS_TERMABLE (DS_ACTIVE | DS_EXTRA_3) #define DS_SIGNABLE (DS_ACTIVE | DS_EXTRA_3)
static MenuItem thread_menu_items[] = @@ -843,8 +873,8 @@ static void on_thread_show_core(const MenuItem *menu_item) { "thread_unsorted", on_thread_unsorted, 0, NULL, NULL }, { "thread_view_source", on_thread_view_source, DS_VIEWABLE, NULL, NULL }, { "thread_synchronize", on_thread_synchronize, DS_SENDABLE, NULL, NULL }, - { "thread_interrupt", on_thread_interrupt, DS_INTRABLE, NULL, NULL }, - { "thread_terminate", on_thread_terminate, DS_TERMABLE, NULL, NULL }, + { "thread_interrupt", on_thread_interrupt, DS_SIGNABLE, NULL, NULL }, + { "thread_terminate", on_thread_terminate, DS_SIGNABLE, NULL, NULL }, #ifdef G_OS_UNIX { "thread_send_signal", on_thread_send_signal, DS_SIGNABLE, NULL, NULL }, #endif @@ -865,10 +895,14 @@ static guint thread_menu_extra_state(void)
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - const char *pid, *file; + char *pid, *file; + gboolean has_pid;
gtk_tree_model_get(model, &iter, THREAD_PID, &pid, THREAD_FILE, &file, -1); - return ((file != NULL) << DS_INDEX_2) | ((utils_atoi0(pid) > 0) << DS_INDEX_3); + has_pid = utils_atoi0(pid) > 0; + g_free(pid); + g_free(file); + return ((file != NULL) << DS_INDEX_2) | (has_pid << DS_INDEX_3); }
return 0; @@ -920,4 +954,5 @@ void thread_finalize(void) model_foreach(model, (GFunc) thread_iter_unmark, NULL); array_free(thread_groups, (GFreeFunc) thread_group_free); set_gdb_thread(NULL, FALSE); + free(thread_id); }
Modified: scope/src/thread.h 4 files changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -34,9 +34,9 @@ THREAD_AT_ASSEMBLER } ThreadState;
-extern const char *thread_id; /* gdb id, NULL if none selected */ +extern char *thread_id; extern ThreadState thread_state; -const char *thread_group_id(void); +char *thread_group_id(void);
void on_thread_running(GArray *nodes); void on_thread_stopped(GArray *nodes);
Modified: scope/src/utils.c 57 files changed, 41 insertions(+), 16 deletions(-) =================================================================== @@ -146,16 +146,16 @@ gchar *array_find(GArray *array, const char *key, G_GNUC_UNUSED gboolean filenam gchar *array_find(GArray *array, const char *key, gboolean filename) #endif { - guint i; - gchar *data = array->data; guint size = g_array_get_element_size(array); + gchar *end = array->data + size * array->len; + gchar *data; #ifdef G_OS_UNIX int (*const compare)(const char *s1, const char *s2) = strcmp; #else int (*compare)(const char *s1, const char *s2) = filename ? utils_str_casecmp : strcmp; #endif
- for (i = 0; i < array->len; i++, data += size) + for (data = array->data; data < end; data += size) if (!compare(*(const char **) data, key)) return data;
@@ -164,11 +164,11 @@ gchar *array_find(GArray *array, const char *key, gboolean filename)
void array_foreach(GArray *array, GFunc each_func, gpointer gdata) { - guint i; - gchar *data = array->data; guint size = g_array_get_element_size(array); + gchar *end = array->data + size * array->len; + gchar *data;
- for (i = 0; i < array->len; i++, data += size) + for (data = array->data; data < end; data += size) each_func(data, gdata); }
@@ -213,11 +213,12 @@ static void utils_clear_sections(GKeyFile *config, const char *prefix, guint i)
void array_save(GArray *array, GKeyFile *config, const gchar *prefix, ASaveFunc save_func) { - guint i, n = 0; - gchar *data = array->data; guint size = g_array_get_element_size(array); + gchar *end = array->data + size * array->len; + gchar *data; + guint n = 0;
- for (i = 0; i < array->len; i++, data += size) + for (data = array->data; data < end; data += size) { char *section = g_strdup_printf("%s_%d", prefix, n); n += save_func(config, section, data); @@ -235,15 +236,24 @@ gboolean model_find(GtkTreeModel *model, GtkTreeIter *iter, guint column, const
while (valid) { + gboolean match; union { - const gchar *s; + gchar *s; gint i; } data;
gtk_tree_model_get(model, iter, column, &data, -1);
- if (string ? g_strcmp0(data.s, key) == 0 : data.i == i) + if (string) + { + match = !g_strcmp0(data.s, key); + g_free(data.s); + } + else + match = data.i == i; + + if (match) return TRUE;
valid = gtk_tree_model_iter_next(model, iter); @@ -285,18 +295,26 @@ void model_save(GtkTreeModel *model, GKeyFile *config, const gchar *prefix,
gint model_string_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gint column) { - const gchar *s1, *s2; + gchar *s1, *s2; + gint result;
gtk_tree_model_get(model, a, column, &s1, -1); gtk_tree_model_get(model, b, column, &s2, -1); - return g_strcmp0(s1, s2); + result = g_strcmp0(s1, s2); + g_free(s1); + g_free(s2); + return result; }
-static int model_atoint(GtkTreeModel *model, GtkTreeIter *iter, gpointer gdata) +static gint model_atoint(GtkTreeModel *model, GtkTreeIter *iter, gpointer gdata) { - const gchar *s; + gchar *s; + gint i; + gtk_tree_model_get(model, iter, GPOINTER_TO_INT(gdata), &s, -1); - return utils_atoi0(s); + i = utils_atoi0(s); + g_free(s); + return i; }
gint model_gint_compare(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer gdata) @@ -567,6 +585,13 @@ gchar *utils_key_file_get_string(GKeyFile *config, const char *section, const ch return string; }
+void utils_key_file_set_string(GKeyFile *config, const char *section, const char *key, + char *value) +{ + g_key_file_set_string(config, section, key, value); + g_free(value); +} + gchar *utils_get_utf8_basename(const char *file) { gchar *utf8 = utils_get_utf8_from_locale(file);
Modified: scope/src/utils.h 2 files changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -87,6 +87,8 @@ void utils_load(GKeyFile *config, const char *prefix, guint utils_parse_sci_color(const gchar *string); gboolean utils_key_file_write_to_file(GKeyFile *config, const char *configfile); gchar *utils_key_file_get_string(GKeyFile *config, const char *section, const char *key); +void utils_key_file_set_string(GKeyFile *config, const char *section, const char *key, + char *value); /* frees value */ gchar *utils_get_utf8_basename(const char *file);
char *utils_7bit_to_locale(char *text); /* == text */
Modified: scope/src/views.c 37 files changed, 25 insertions(+), 12 deletions(-) =================================================================== @@ -40,7 +40,7 @@ { FALSE, stack_clear, stack_update, TRUE, DS_DEBUG }, { FALSE, locals_clear, locals_update, TRUE, DS_DEBUG }, { FALSE, watches_clear, watches_update, TRUE, DS_DEBUG }, - { FALSE, memory_clear, memory_update, FALSE, DS_SENDABLE }, + { FALSE, memory_clear, memory_update, TRUE, DS_SENDABLE }, { FALSE, NULL, dc_update, FALSE, DS_DEBUG }, { FALSE, inspects_clear, inspects_update, FALSE, DS_DEBUG }, { FALSE, tooltip_clear, tooltip_update, FALSE, DS_SENDABLE }, @@ -143,9 +143,9 @@ void views_update(DebugState state) } }
-gboolean view_select_frame(void) +gboolean view_stack_update(void) { - if (g_strcmp0(frame_id, "0") && views[VIEW_STACK].dirty) + if (views[VIEW_STACK].dirty) { DebugState state = thread_state >= THREAD_STOPPED ? DS_DEBUG : DS_READY; view_update_unconditional(VIEW_STACK, state); @@ -199,7 +199,7 @@ gboolean on_view_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keybo
if (gtk_tree_view_get_tooltip_context(tree, &x, &y, keyboard_tip, NULL, NULL, &iter)) { - const char *file; + char *file;
gtk_tree_view_set_tooltip_cell(tree, tooltip, NULL, base_name_column, NULL); gtk_tree_model_get(gtk_tree_view_get_model(tree), &iter, COLUMN_FILE, &file, -1); @@ -209,6 +209,7 @@ gboolean on_view_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keybo gchar *utf8 = utils_get_utf8_from_locale(file);
gtk_tooltip_set_text(tooltip, utf8); + g_free(file); g_free(utf8); return TRUE; } @@ -250,7 +251,7 @@ static void on_display_editing_started(G_GNUC_UNUSED GtkCellRenderer *cell, GtkCellEditable *editable, const gchar *path_str, GtkTreeModel *model) { GtkTreeIter iter; - const char *value; + char *value; gint hb_mode;
g_assert(GTK_IS_EDITABLE(editable)); @@ -259,6 +260,7 @@ static void on_display_editing_started(G_GNUC_UNUSED GtkCellRenderer *cell, /* scrolling editable to the proper position is left as an exercise for the reader */ g_signal_connect(editable, "map-event", G_CALLBACK(on_display_editable_map_event), parse_get_display_from_7bit(value, hb_mode, MR_EDITVC)); + g_free(value); }
GtkTreeView *view_connect(const char *name, GtkTreeModel **model, GtkTreeSelection **selection, @@ -331,7 +333,7 @@ void view_display_edited(GtkTreeModel *model, gboolean condition, const gchar *p if (condition) { GtkTreeIter iter; - const char *name; + char *name; gint hb_mode; char *locale;
@@ -341,6 +343,7 @@ void view_display_edited(GtkTreeModel *model, gboolean condition, const gchar *p locale = utils_get_locale_from_display(new_text, hb_mode); utils_strchrepl(locale, '\n', ' '); debug_send_format(F, format, name, locale); + g_free(name); g_free(locale); } else @@ -357,14 +360,19 @@ void view_seek_selected(GtkTreeSelection *selection, gboolean focus, SeekerType { GtkTreeModel *model; GtkTreeIter iter; - const char *file; - gint line;
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { + char *file; + gint line; + gtk_tree_model_get(model, &iter, COLUMN_FILE, &file, COLUMN_LINE, &line, -1); + if (file) + { utils_seek(file, line, focus, seeker); + g_free(file); + } } }
@@ -428,7 +436,7 @@ static void on_command_history_changed(GtkComboBox *command_history,
if (gtk_combo_box_get_active_iter(command_history, &iter)) { - const gchar *text; + gchar *text; gboolean locale;
gtk_tree_model_get(command_model, &iter, COMMAND_TEXT, &text, COMMAND_LOCALE, @@ -437,24 +445,29 @@ static void on_command_history_changed(GtkComboBox *command_history, gtk_toggle_button_set_active(command_locale, locale); gtk_widget_grab_focus(command_view); gtk_combo_box_set_active_iter(command_history, NULL); + g_free(text); } }
static void on_command_insert_button_clicked(G_GNUC_UNUSED GtkButton *button, gpointer gdata) { - const char *prefix, *id; + const char *prefix; + char *id; GString *text = g_string_new("--");
switch (GPOINTER_TO_INT(gdata)) { - case 't' : prefix = "thread"; id = thread_id; break; + case 't' : prefix = "thread"; id = g_strdup(thread_id); break; case 'g' : prefix = "group"; id = thread_group_id(); break; - default : prefix = "frame"; id = frame_id; + default : prefix = "frame"; id = g_strdup(frame_id); }
g_string_append_printf(text, "%s ", prefix); if (id) + { g_string_append_printf(text, "%s ", id); + g_free(id); + } gtk_text_buffer_delete_selection(command_text, FALSE, TRUE); gtk_text_buffer_insert_at_cursor(command_text, text->str, -1); g_string_free(text, TRUE);
Modified: scope/src/views.h 2 files changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -39,7 +39,7 @@ void views_data_dirty(void); void views_clear(void); void views_update(DebugState state); -gboolean view_select_frame(void); +gboolean view_stack_update(void); void view_inspect_update(void);
void on_view_changed(GtkNotebook *notebook, gpointer page, gint page_num, gpointer gdata);
Modified: scope/src/watch.c 13 files changed, 8 insertions(+), 5 deletions(-) =================================================================== @@ -51,7 +51,7 @@ static void on_watch_enabled_toggled(G_GNUC_UNUSED GtkCellRendererToggle *render
static void watch_iter_update(GtkTreeIter *iter, gpointer gdata) { - const gchar *expr; + gchar *expr; gint scid; gboolean enabled;
@@ -60,6 +60,7 @@ static void watch_iter_update(GtkTreeIter *iter, gpointer gdata)
if (enabled || GPOINTER_TO_INT(gdata)) g_free(debug_send_evaluate('6', scid, expr)); + g_free(expr); }
static void on_watch_expr_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, @@ -68,7 +69,7 @@ static void on_watch_expr_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, if (validate_column(new_text, TRUE)) { GtkTreeIter iter; - const gchar *expr; + gchar *expr; gboolean enabled;
gtk_tree_model_get_iter_from_string(model, &iter, path_str); @@ -85,6 +86,7 @@ static void on_watch_expr_edited(G_GNUC_UNUSED GtkCellRendererText *renderer, if (enabled && (debug_state() & DS_DEBUG)) watch_iter_update(&iter, GINT_TO_POINTER(TRUE)); } + g_free(expr); } }
@@ -161,7 +163,7 @@ void watches_clear(void)
gboolean watches_update(void) { - if (view_select_frame()) + if (g_strcmp0(frame_id, "0") && view_stack_update()) return FALSE;
model_foreach(model, (GFunc) watch_iter_update, GPOINTER_TO_INT(FALSE)); @@ -241,7 +243,7 @@ static gboolean watch_save(GKeyFile *config, const char *section, GtkTreeIter *i
gtk_tree_model_get(model, iter, WATCH_EXPR, &expr, WATCH_HB_MODE, &hb_mode, WATCH_MR_MODE, &mr_mode, WATCH_ENABLED, &enabled, -1); - g_key_file_set_string(config, section, "expr", expr); + utils_key_file_set_string(config, section, "expr", expr); g_key_file_set_integer(config, section, "hbit", hb_mode); g_key_file_set_integer(config, section, "member", mr_mode); g_key_file_set_boolean(config, section, "enabled", enabled); @@ -267,12 +269,13 @@ static void on_watch_unsorted(G_GNUC_UNUSED const MenuItem *menu_item) static void on_watch_add(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - const gchar *expr = NULL; + gchar *expr = NULL;
if (gtk_tree_selection_get_selected(selection, NULL, &iter)) gtk_tree_model_get(model, &iter, WATCH_EXPR, &expr, -1);
watch_add(expr); + g_free(expr); }
static void on_watch_copy(const MenuItem *menu_item)
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org