Revision: 2123 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2123&view=re... Author: cesspit Date: 2011-08-06 10:15:27 +0000 (Sat, 06 Aug 2011)
Log Message: ----------- debugger plugin: - fixing bug with the breakpoint removing when deleting a corresponding line from the document - some refactoring
Modified Paths: -------------- trunk/geany-plugins/debugger/src/breakpoints.c trunk/geany-plugins/debugger/src/breakpoints.h trunk/geany-plugins/debugger/src/callbacks.c trunk/geany-plugins/debugger/src/debug.c trunk/geany-plugins/debugger/src/tpage.c trunk/geany-plugins/debugger/src/utils.c trunk/geany-plugins/debugger/src/utils.h
Modified: trunk/geany-plugins/debugger/src/breakpoints.c =================================================================== --- trunk/geany-plugins/debugger/src/breakpoints.c 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/breakpoints.c 2011-08-06 10:15:27 UTC (rev 2123) @@ -44,10 +44,12 @@ * Functions for breakpoint iteration support */
+typedef void (*breaks_iterate_function)(void* bp); + /* * Iterates through GTree for the particular file */ -gboolean tree_foreach(gpointer key, gpointer value, gpointer data) +gboolean tree_foreach_call_function(gpointer key, gpointer value, gpointer data) { ((breaks_iterate_function)data)(value); return FALSE; @@ -56,16 +58,46 @@ /* * Iterates through hash table of GTree-s */ -void hash_table_foreach(gpointer key, gpointer value, gpointer user_data) +void hash_table_foreach_call_function(gpointer key, gpointer value, gpointer user_data) { - g_tree_foreach((GTree*)value, tree_foreach, user_data); + g_tree_foreach((GTree*)value, tree_foreach_call_function, user_data); }
/* + * Iterates through GTree + * adding each item to GList that is passed through data variable + */ +gboolean tree_foreach_add_to_list(gpointer key, gpointer value, gpointer data) +{ + GList **list = (GList**)data; + *list = g_list_append(*list, value); + return FALSE; +} + +/* + * Iterates through hash table of GTree-s + * calling list collection functions on each tree + */ +void hash_table_foreach_add_to_list(gpointer key, gpointer value, gpointer user_data) +{ + g_tree_foreach((GTree*)value, tree_foreach_add_to_list, user_data); +} + +/* * Helper functions */
/* + * Remove breakpoint while iterating through GTree. + * arguments: + * bp - breakpoint + */ +void breaks_remove_internal(breakpoint *bp) +{ + handle_break_remove(bp, TRUE); +} + +/* * lookup for breakpoint * arguments: * file - breakpoints filename @@ -260,7 +292,15 @@ void breaks_destroy() { /* remove all markers */ - breaks_iterate((breaks_iterate_function)markers_remove_breakpoint); + GList *breaks, *iter; + breaks = iter = breaks_get_all(); + while (iter) + { + markers_remove_breakpoint((breakpoint*)iter->data); + iter = iter->next; + } + g_list_free(breaks); + /* free storage */ g_hash_table_destroy(files); } @@ -333,6 +373,16 @@ }
/* + * Removes all breakpoints. + * arguments: + */ +void breaks_remove_all() +{ + g_hash_table_foreach(files, hash_table_foreach_call_function, (gpointer)breaks_remove_internal); + g_hash_table_remove_all(files); +} + +/* * Switch breakpoints state. * arguments: * file - breakpoints filename @@ -425,6 +475,30 @@ }
/* + * Moves a breakpoint from to another line + * arguments: + * file - breakpoints filename + * line_from - old line number + * line_to - new line number + */ +void breaks_move_to_line(char* file, int line_from, int line_to) +{ + /* first look for the tree for the given file */ + GTree *tree = NULL; + if (tree = g_hash_table_lookup(files, file)) + { + /* lookup for the break in GTree*/ + breakpoint *bp = (breakpoint*)g_tree_lookup(tree, GINT_TO_POINTER(line_from)); + if (bp) + { + g_tree_steal(tree, GINT_TO_POINTER(line_from)); + bp->line = line_to; + g_tree_insert(tree, GINT_TO_POINTER(line_to), bp); + } + } +} + +/* * Checks whether breakpoint is set. * arguments: * file - breakpoints filename @@ -449,25 +523,32 @@ * arguments: * file - file name to get breaks for */ -GTree *breaks_get_for_document(char* file) +GList *breaks_get_for_document(char* file) { - return g_hash_table_lookup(files, file); + GList *breaks = NULL; + GTree *tree = g_hash_table_lookup(files, file); + if (tree) + { + g_tree_foreach(tree, tree_foreach_add_to_list, &breaks); + } + return breaks; }
/* - * Get breakpoints widget + * Gets all breakpoints + * arguments: */ -GtkWidget* breaks_get_widget() +GList* breaks_get_all() { - return bptree_get_widget(); + GList *breaks = NULL; + g_hash_table_foreach(files, hash_table_foreach_add_to_list, &breaks); + return breaks; }
/* - * Calls specified function on every breakpoint - * arguments: - * bif - function to call + * Get breakpoints widget */ -void breaks_iterate(breaks_iterate_function bif) +GtkWidget* breaks_get_widget() { - g_hash_table_foreach(files, hash_table_foreach, (gpointer)bif); + return bptree_get_widget(); }
Modified: trunk/geany-plugins/debugger/src/breakpoints.h =================================================================== --- trunk/geany-plugins/debugger/src/breakpoints.h 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/breakpoints.h 2011-08-06 10:15:27 UTC (rev 2123) @@ -20,16 +20,18 @@ */
typedef void (*move_to_line_cb)(char* file, int line); -typedef void (*breaks_iterate_function)(void* bp);
gboolean breaks_init(move_to_line_cb callback); void breaks_destroy(); void breaks_add(char* file, int line, char* condition, int enable, int hitscount); void breaks_remove(char* file, int line); +void breaks_remove_all(); void breaks_switch(char* file, int line); void breaks_set_hits_count(char* file, int line, int count); void breaks_set_condition(char* file, int line, char* condition); -void breaks_iterate(breaks_iterate_function bif); +void breaks_move_to_line(char* file, int line_from, int line_to); gboolean breaks_is_set(char* file, int line); GtkWidget* breaks_get_widget(); -GTree* breaks_get_for_document(char* file); +GList* breaks_get_for_document(char* file); +GList* breaks_get_all(); +
Modified: trunk/geany-plugins/debugger/src/callbacks.c =================================================================== --- trunk/geany-plugins/debugger/src/callbacks.c 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/callbacks.c 2011-08-06 10:15:27 UTC (rev 2123) @@ -98,9 +98,19 @@ /* check if current path contains config file */ tpage_on_document_activate(doc);
- GTree *tree; - if (tree = breaks_get_for_document(file)) - g_tree_foreach(tree, tree_foreach_set_marker, NULL); + GList *breaks; + if (breaks = breaks_get_for_document(file)) + { + GList *iter = breaks; + while (iter) + { + breakpoint *bp = (breakpoint*)iter->data; + markers_add_breakpoint(bp); + + iter = iter->next; + } + g_list_free(breaks); + }
/* if debug is active - tell the debug module that a file was opened */ if (DBS_IDLE != debug_get_state()) @@ -174,21 +184,17 @@ { int line = sci_get_line_from_position(editor->sci, nt->position) + 1;
- GTree *breakpoints = breaks_get_for_document(editor->document->file_name); - if (breakpoints && g_tree_nnodes(breakpoints)) + GList *breaks = breaks_get_for_document(editor->document->file_name); + if (breaks) { - - GList *breaks_list = NULL; - g_tree_foreach(breakpoints, tree_foreach_add_to_list, &breaks_list); - - GList *iter = breaks_list; + GList *iter = breaks; while (iter) { breakpoint *bp = (breakpoint*)iter->data;
if (nt->linesAdded > 0 && bp->line >= line) { - bp->line += nt->linesAdded; + breaks_move_to_line(bp->file, bp->line, bp->line + nt->linesAdded); bptree_update_breakpoint(bp); } else if (nt->linesAdded < 0 && bp->line >= line) @@ -199,14 +205,14 @@ } else { - bp->line += nt->linesAdded; + breaks_move_to_line(bp->file, bp->line, bp->line + nt->linesAdded); bptree_update_breakpoint(bp); } } iter = iter->next; }
- g_list_free(breaks_list); + g_list_free(breaks); } } break;
Modified: trunk/geany-plugins/debugger/src/debug.c =================================================================== --- trunk/geany-plugins/debugger/src/debug.c 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/debug.c 2011-08-06 10:15:27 UTC (rev 2123) @@ -772,21 +772,6 @@ };
/* - * iterating staff to add breakpoints on startup - * erroneous_break - pointer to the breakpoint that caused error - * when setting. - */ -breakpoint* erroneous_break; -void set_new_break(void* bp) -{ - if (erroneous_break) - return; - - if(!active_module->set_break((breakpoint*)bp, BSA_NEW_BREAK)) - erroneous_break = (breakpoint*)bp; -} - -/* * Interface functions */
@@ -1000,14 +985,26 @@ if (active_module->load(target, commandline, env, watches)) { /* set breaks */ - erroneous_break = NULL; - breaks_iterate(set_new_break); - - if (erroneous_break) + + GList *breaks = breaks_get_all(); + + GList *iter = breaks; + while (iter) { + breakpoint *bp = (breakpoint*)iter->data; + if(!active_module->set_break(bp, BSA_NEW_BREAK)) + { + break; + } + iter = iter->next; + } + + if (iter) + { + breakpoint *bad_break = (breakpoint*)iter->data; gchar msg[1000]; sprintf(msg, _("Breakpoint at %s:%i cannot be set\nDebugger message: %s"), - erroneous_break->file, erroneous_break->line, active_module->error_message()); + bad_break->file, bad_break->line, active_module->error_message()); dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", msg); @@ -1015,6 +1012,8 @@ debug_state = DBS_STOP_REQUESTED; return; } + + g_list_free(breaks); /* set target page - readonly */ tpage_set_readonly(TRUE);
Modified: trunk/geany-plugins/debugger/src/tpage.c =================================================================== --- trunk/geany-plugins/debugger/src/tpage.c 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/tpage.c 2011-08-06 10:15:27 UTC (rev 2123) @@ -406,15 +406,6 @@ }
/* - * GList and function to collect breaks from breakpoints page to save in config - */ -GList *breaks = NULL; -void collect_breaks(void* bp) -{ - breaks = g_list_append(breaks, bp); -} - -/* * save config */ void on_save_config(GtkButton *button, gpointer user_data) @@ -470,7 +461,7 @@ while (gtk_tree_model_iter_next(model, &iter));
/* breakpoints */ - breaks_iterate(collect_breaks); + GList *breaks = breaks_get_all(); GList *biter = breaks; while (biter) { @@ -525,16 +516,6 @@ }
/* - * function to remove a break when loading config and iterating through - * existing breaks - */ -void removebreak(void *p) -{ - breakpoint *bp = (breakpoint*)p; - breaks_remove(bp->file, bp->line); -} - -/* * load config file */ void on_load_config(GtkButton *button, gpointer user_data) @@ -565,9 +546,9 @@ readline(config, arguments, FILENAME_MAX - 1); GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_text_buffer_set_text(buffer, arguments, -1); - + /* breakpoints and environment variables */ - breaks_iterate(removebreak); + breaks_remove_all(); wtree_remove_all(); gboolean wrongbreaks = FALSE; @@ -647,7 +628,7 @@ void on_clear(GtkButton *button, gpointer user_data) { /* breakpoints */ - breaks_iterate(removebreak); + breaks_remove_all();
/* watches */ wtree_remove_all();
Modified: trunk/geany-plugins/debugger/src/utils.c =================================================================== --- trunk/geany-plugins/debugger/src/utils.c 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/utils.c 2011-08-06 10:15:27 UTC (rev 2123) @@ -103,26 +103,6 @@ }
/* - * GTree iteration functions that sets marker for each breakpoint in the tree - */ -gboolean tree_foreach_set_marker(gpointer key, gpointer value, gpointer data) -{ - breakpoint *bp = (breakpoint*)value; - markers_add_breakpoint(bp); - return FALSE; -} - -/* - * GTree iteration functions that adds data to the list supplied in "data" parameter - */ -gboolean tree_foreach_add_to_list(gpointer key, gpointer value, gpointer data) -{ - GList **list = (GList**)data; - *list = g_list_append(*list, value); - return FALSE; -} - -/* * get word at "position" in Scintilla document */ GString* get_word_at_position(ScintillaObject *sci, int position)
Modified: trunk/geany-plugins/debugger/src/utils.h =================================================================== --- trunk/geany-plugins/debugger/src/utils.h 2011-08-06 06:02:50 UTC (rev 2122) +++ trunk/geany-plugins/debugger/src/utils.h 2011-08-06 10:15:27 UTC (rev 2123) @@ -23,6 +23,4 @@ int get_char_width(GtkWidget *widget); int get_header_string_width(gchar *header, int minchars, int char_width); GtkTreeViewColumn* create_column(gchar *name, GtkCellRenderer *renderer, gboolean expandable, gint minwidth, gchar *arg, int value); -gboolean tree_foreach_set_marker(gpointer key, gpointer value, gpointer data); GString* get_word_at_position(ScintillaObject *sci, int position); -gboolean tree_foreach_add_to_list(gpointer key, gpointer value, gpointer data);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.