Skip to content

Commit

Permalink
Merge branch 'debugger/frame-speedup' into debugger/master
Browse files Browse the repository at this point in the history
Closes #347.
  • Loading branch information
b4n committed Feb 7, 2016
2 parents 5d3df6c + 8642062 commit 138e3d3
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 207 deletions.
6 changes: 3 additions & 3 deletions debugger/src/breakpoints.c
Expand Up @@ -70,7 +70,7 @@ static void hash_table_foreach_call_function(gpointer key, gpointer value, gpoin
static gboolean tree_foreach_add_to_list(gpointer key, gpointer value, gpointer data)
{
GList **list = (GList**)data;
*list = g_list_append(*list, value);
*list = g_list_prepend(*list, value);
return FALSE;
}

Expand Down Expand Up @@ -675,7 +675,7 @@ GList* breaks_get_for_document(const char* file)
{
g_tree_foreach(tree, tree_foreach_add_to_list, &breaks);
}
return breaks;
return g_list_reverse(breaks);
}

/*
Expand All @@ -702,5 +702,5 @@ GList* breaks_get_all(void)
{
GList *breaks = NULL;
g_hash_table_foreach(files, hash_table_foreach_add_to_list, &breaks);
return breaks;
return g_list_reverse(breaks);
}
14 changes: 8 additions & 6 deletions debugger/src/dbm_gdb.c
Expand Up @@ -213,10 +213,10 @@ static GList* read_until_prompt(void)
break;

line[terminator] = '\0';
lines = g_list_append (lines, line);
lines = g_list_prepend (lines, line);
}

return lines;
return g_list_reverse(lines);
}

/*
Expand Down Expand Up @@ -1129,11 +1129,11 @@ static GList* get_stack(void)
/* line */
f->line = line ? atoi(line) : 0;

stack = g_list_append(stack, f);
stack = g_list_prepend(stack, f);
}
gdb_mi_record_free(record);

return stack;
return g_list_reverse(stack);
}

/*
Expand Down Expand Up @@ -1293,8 +1293,9 @@ static void update_watches(void)
var->evaluated = name != NULL;

/* add to updating list */
updating = g_list_append(updating, var);
updating = g_list_prepend(updating, var);
}
updating = g_list_reverse(updating);

/* update watches */
get_variables(updating);
Expand Down Expand Up @@ -1465,11 +1466,12 @@ static GList* get_children (gchar* path)
var = variable_new2(name, internal, VT_CHILD);
var->evaluated = TRUE;

children = g_list_append(children, var);
children = g_list_prepend(children, var);
}
}
gdb_mi_record_free(record);

children = g_list_reverse(children);
get_variables(children);

return children;
Expand Down
20 changes: 8 additions & 12 deletions debugger/src/debug.c
Expand Up @@ -418,13 +418,13 @@ static gboolean on_watch_key_pressed_callback(GtkWidget *widget, GdkEvent *even

/* add path reference if it's not an empty row*/
if (gtk_tree_path_compare(path, empty_path))
references = g_list_append(references, gtk_tree_row_reference_new(wmodel, path));
references = g_list_prepend(references, gtk_tree_row_reference_new(wmodel, path));

iter = iter->next;
}

/* iterate through references and remove */
iter = references;
iter = g_list_reverse(references);
while (iter)
{
GtkTreeRowReference *reference = (GtkTreeRowReference*)iter->data;
Expand Down Expand Up @@ -640,7 +640,7 @@ static void on_debugger_run (void)
if (stack)
{
remove_stack_markers();
g_list_foreach(stack, (GFunc)frame_free, NULL);
g_list_foreach(stack, (GFunc)frame_unref, NULL);
g_list_free(stack);
stack = NULL;

Expand Down Expand Up @@ -700,11 +700,7 @@ static void on_debugger_stopped (int thread_id)

/* get current stack trace and put in the tree view */
stack = active_module->get_stack();
for (iter = stack; iter; iter = iter->next)
{
frame *f = (frame*)iter->data;
stree_add(f);
}
stree_add (stack);
stree_select_first_frame(TRUE);

/* files */
Expand Down Expand Up @@ -799,7 +795,7 @@ static void on_debugger_exited (int code)
if (stack)
{
remove_stack_markers();
g_list_foreach(stack, (GFunc)frame_free, NULL);
g_list_foreach(stack, (GFunc)frame_unref, NULL);
g_list_free(stack);
stack = NULL;
}
Expand Down Expand Up @@ -1075,7 +1071,7 @@ void debug_destroy(void)
if (stack)
{
remove_stack_markers();
g_list_foreach(stack, (GFunc)frame_free, NULL);
g_list_foreach(stack, (GFunc)frame_unref, NULL);
g_list_free(stack);
stack = NULL;
}
Expand Down Expand Up @@ -1126,11 +1122,11 @@ GList* debug_get_modules(void)
module_description *desc = modules;
while (desc->title)
{
mods = g_list_append(mods, (gpointer)desc->title);
mods = g_list_prepend(mods, (gpointer)desc->title);
desc++;
}

return mods;
return g_list_reverse(mods);
}

/*
Expand Down
28 changes: 15 additions & 13 deletions debugger/src/debug_module.c
Expand Up @@ -79,26 +79,28 @@ void variable_reset(variable *var)
/* creates new frame */
frame* frame_new(void)
{
frame *f = (frame*)malloc(sizeof(frame));
memset((void*)f, 0, sizeof(frame));
frame *f = g_malloc0(sizeof *f);
f->ref_count = 1;
return f;
}

/* frees a frame */
void frame_free(frame* f)
/* refs a frame */
frame* frame_ref(frame* f)
{
if (f->address)
f->ref_count++;
return f;
}

/* unrefs a frame */
void frame_unref(frame* f)
{
if (f->ref_count > 1)
f->ref_count--;
else
{
g_free(f->address);
}
if (f->function)
{
g_free(f->function);
}
if (f->file)
{
g_free(f->file);
g_free(f);
}

g_free(f);
}
6 changes: 4 additions & 2 deletions debugger/src/debug_module.h
Expand Up @@ -79,6 +79,7 @@ typedef struct _variable {

/* type to hold information about a stack frame */
typedef struct _frame {
gint ref_count;
gchar *address;
gchar *function;
gchar *file;
Expand Down Expand Up @@ -170,7 +171,8 @@ variable* variable_new(const gchar *name, variable_type vt);
variable* variable_new2(const gchar *name, const gchar *internal, variable_type vt);
void variable_reset(variable *var);

frame* frame_new(void);
void frame_free(frame* f);
frame* frame_new(void);
frame* frame_ref(frame* f);
void frame_unref(frame* f);

#endif /* guard */
4 changes: 2 additions & 2 deletions debugger/src/envtree.c
Expand Up @@ -135,7 +135,7 @@ static void delete_selected_rows(void)
}

if (gtk_tree_path_compare(path, empty_path))
references = g_list_append(references, gtk_tree_row_reference_new(model, path));
references = g_list_prepend(references, gtk_tree_row_reference_new(model, path));

iter = iter->next;
}
Expand All @@ -145,7 +145,7 @@ static void delete_selected_rows(void)
if (!reference_to_select)
reference_to_select = gtk_tree_row_reference_copy (empty_row);

iter = references;
iter = g_list_reverse(references);
while (iter)
{
GtkTreeIter titer;
Expand Down
51 changes: 36 additions & 15 deletions debugger/src/gdb_mi.c
Expand Up @@ -98,13 +98,17 @@ static gchar *parse_cstring(const gchar **p)

if (**p == '"')
{
const gchar *base;

(*p)++;
base = *p;
while (**p != '"')
{
gchar c = **p;
/* TODO: check expansions here */
if (c == '\\')
{
g_string_append_len(str, base, (*p) - base);
(*p)++;
c = **p;
switch (g_ascii_tolower(c))
Expand Down Expand Up @@ -159,12 +163,14 @@ static gchar *parse_cstring(const gchar **p)
}
break;
}
g_string_append_c(str, c);
base = (*p) + 1;
}
if (**p == '\0')
else if (**p == '\0')
break;
g_string_append_c(str, c);
(*p)++;
}
g_string_append_len(str, base, (*p) - base);
if (**p == '"')
(*p)++;
}
Expand All @@ -176,15 +182,15 @@ static gchar *parse_cstring(const gchar **p)
* the docs aren't clear on this */
static gchar *parse_string(const gchar **p)
{
GString *str = g_string_new(NULL);
const gchar *base = *p;

if (g_ascii_isalpha(**p) || strchr("-_.", **p))
{
g_string_append_c(str, **p);
for ((*p)++; g_ascii_isalnum(**p) || strchr("-_.", **p); (*p)++)
g_string_append_c(str, **p);
;
}
return g_string_free(str, FALSE);

return g_strndup (base, *p - base);
}

/* parses: string "=" value */
Expand All @@ -205,15 +211,17 @@ static gboolean parse_result(struct gdb_mi_result *result, const gchar **p)
* Actually, this is more permissive and allows mixed tuples/lists */
static struct gdb_mi_value *parse_value(const gchar **p)
{
struct gdb_mi_value *val = g_malloc0(sizeof *val);
struct gdb_mi_value *val = NULL;
if (**p == '"')
{
val = g_malloc0(sizeof *val);
val->type = GDB_MI_VAL_STRING;
val->string = parse_cstring(p);
}
else if (**p == '{' || **p == '[')
{
struct gdb_mi_result *prev = NULL;
val = g_malloc0(sizeof *val);
val->type = GDB_MI_VAL_LIST;
gchar end = **p == '{' ? '}' : ']';
(*p)++;
Expand Down Expand Up @@ -242,11 +250,6 @@ static struct gdb_mi_value *parse_value(const gchar **p)
if (**p == end)
(*p)++;
}
else
{
gdb_mi_value_free(val);
val = NULL;
}
return val;
}

Expand Down Expand Up @@ -479,17 +482,35 @@ static void gdb_mi_record_dump(const struct gdb_mi_record *record)
gdb_mi_result_dump(record->first, TRUE, 2);
}

int main(void)
static gchar *read_line(FILE *fp)
{
char buf[1024] = {0};
GString *line = g_string_new(NULL);

while (fgets(buf, sizeof buf, fp))
{
g_string_append(line, buf);
if (line->len < 1 || line->str[line->len - 1] == '\n')
break;
}

return g_string_free(line, line->len < 1);
}

while (fgets(buf, sizeof buf, stdin))
int main(int argc, char **argv)
{
gchar *line;

while ((line = read_line(stdin)) != NULL)
{
struct gdb_mi_record *record = gdb_mi_record_parse(buf);
struct gdb_mi_record *record = gdb_mi_record_parse(line);

gdb_mi_record_dump(record);
gdb_mi_record_free(record);

g_free(line);
}

return 0;
}

Expand Down

0 comments on commit 138e3d3

Please sign in to comment.