Skip to content

Commit

Permalink
Merge branch 'debugger/thread-support' into debugger/master
Browse files Browse the repository at this point in the history
  • Loading branch information
b4n committed Feb 9, 2016
2 parents d21c653 + ca9abb6 commit fb28b3d
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 18 deletions.
1 change: 1 addition & 0 deletions debugger/src/breakpoints.h
Expand Up @@ -33,6 +33,7 @@ typedef enum _break_state {
} break_state;

typedef void (*move_to_line_cb)(const char* file, int line);
typedef void (*select_thread_cb)(int thread_id);
typedef void (*select_frame_cb)(int frame_number);

gboolean breaks_init(move_to_line_cb callback);
Expand Down
28 changes: 28 additions & 0 deletions debugger/src/dbm_gdb.c
Expand Up @@ -1082,6 +1082,34 @@ static void set_active_frame(int frame_number)
g_free(command);
}

static int get_active_thread(void)
{
struct gdb_mi_record *record = NULL;
int current_thread = 0;

if (RC_DONE == exec_sync_command("-thread-info", TRUE, &record))
{
const gchar *id = gdb_mi_result_var(record->first, "current-thread-id", GDB_MI_VAL_STRING);
current_thread = id ? atoi(id) : 0;
}
gdb_mi_record_free(record);

return current_thread;
}

static gboolean set_active_thread(int thread_id)
{
gchar *command = g_strdup_printf("-thread-select %i", thread_id);
gboolean success = (RC_DONE == exec_sync_command(command, TRUE, NULL));

if (success)
set_active_frame(0);

g_free(command);

return success;
}

/*
* gets stack
*/
Expand Down
31 changes: 30 additions & 1 deletion debugger/src/debug.c
Expand Up @@ -959,6 +959,35 @@ static void on_select_frame(int frame_number)
}
}

/*
* called when a thread should been selected
*/
static void on_select_thread(int thread_id)
{
gboolean success;

if (stack)
remove_stack_markers();

if ((success = active_module->set_active_thread(thread_id)))
{
g_list_free_full(stack, (GDestroyNotify)frame_unref);
stack = active_module->get_stack();

/* update the stack tree */
stree_remove_frames();
stree_set_active_thread_id(thread_id);
stree_add(stack);
stree_select_first_frame(TRUE);
}

if (stack)
add_stack_markers();

if (success)
on_select_frame(0);
}

/*
* init debug related GUI (watch tree view)
* arguments:
Expand Down Expand Up @@ -1002,7 +1031,7 @@ void debug_init(void)
gtk_container_add(GTK_CONTAINER(tab_autos), atree);

/* create stack trace page */
stree = stree_init(editor_open_position, on_select_frame);
stree = stree_init(editor_open_position, on_select_thread, on_select_frame);
tab_call_stack = gtk_scrolled_window_new(
gtk_tree_view_get_hadjustment(GTK_TREE_VIEW(stree )),
gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(stree ))
Expand Down
7 changes: 6 additions & 1 deletion debugger/src/debug_module.h
Expand Up @@ -121,7 +121,10 @@ typedef struct _dbg_module {

void (*set_active_frame)(int frame_number);
int (*get_active_frame)(void);


gboolean (*set_active_thread)(int thread_id);
int (*get_active_thread)(void);

GList* (*get_autos) (void);
GList* (*get_watches) (void);

Expand Down Expand Up @@ -155,6 +158,8 @@ typedef struct _dbg_module {
get_stack, \
set_active_frame, \
get_active_frame, \
set_active_thread, \
get_active_thread, \
get_autos, \
get_watches, \
get_files, \
Expand Down
31 changes: 16 additions & 15 deletions debugger/src/stree.c
Expand Up @@ -54,6 +54,7 @@ static int active_frame_index = 0;

/* callbacks */
static select_frame_cb select_frame = NULL;
static select_thread_cb select_thread = NULL;
static move_to_line_cb move_to_line = NULL;

/* tree view, model and store handles */
Expand Down Expand Up @@ -284,33 +285,32 @@ static gboolean on_msgwin_button_press(GtkWidget *widget, GdkEventButton *event,
static void on_cursor_changed(GtkTreeView *treeview, gpointer user_data)
{
GtkTreePath *path;
GtkTreeIter iter;
frame *f;
int thread_id;

gtk_tree_view_get_cursor(treeview, &path, NULL);
if (! path)
return;

if (2 == gtk_tree_path_get_depth(path))
{
frame *f;
GtkTreeIter iter;
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter,
S_FRAME, &f, S_THREAD_ID, &thread_id, -1);

gtk_tree_model_get_iter (
model,
&iter,
path);
gtk_tree_model_get (
gtk_tree_view_get_model(GTK_TREE_VIEW(tree)),
&iter,
S_FRAME, &f,
-1);

if (f) /* frame */
{
/* check if file name is not empty and we have source files for the frame */
if (f->have_source)
{
move_to_line(f->file, f->line);
}
frame_unref(f);
}
else /* thread */
{
if (thread_id != active_thread_id)
select_thread(thread_id);
}

gtk_tree_path_free(path);
}
Expand Down Expand Up @@ -356,12 +356,13 @@ static void on_render_address (GtkTreeViewColumn *tree_column, GtkCellRenderer *
/*
* inits stack trace tree
*/
GtkWidget* stree_init(move_to_line_cb ml, select_frame_cb sf)
GtkWidget* stree_init(move_to_line_cb ml, select_thread_cb st, select_frame_cb sf)
{
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;

move_to_line = ml;
select_thread = st;
select_frame = sf;

/* create tree view */
Expand Down
2 changes: 1 addition & 1 deletion debugger/src/stree.h
Expand Up @@ -28,7 +28,7 @@
#include "breakpoints.h"
#include "debug_module.h"

GtkWidget* stree_init(move_to_line_cb ml, select_frame_cb sf);
GtkWidget* stree_init(move_to_line_cb ml, select_thread_cb st, select_frame_cb sf);
void stree_destroy(void);

void stree_add(GList *frames);
Expand Down

0 comments on commit fb28b3d

Please sign in to comment.