1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
stack_trace.c
Copyright (C) 2000 Kh. Naba Kumar Singh
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "stack_trace.h"
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
/*#define DEBUG*/
#include <libanjuta/resources.h>
#include <libanjuta/anjuta-debug.h>
#include <libanjuta/interfaces/ianjuta-editor.h>
#include <libanjuta/interfaces/ianjuta-document-manager.h>
#include "utilities.h"
#include "info.h"
#include "queue.h"
#define ANJUTA_PIXMAP_POINTER PACKAGE_PIXMAPS_DIR"/pointer.png"
typedef struct _DmaThreadStackTrace
{
GtkTreeModel *model;
gint thread;
guint last_update;
} DmaThreadStackTrace;
struct _StackTrace
{
DebugManagerPlugin *plugin;
DmaDebuggerQueue *debugger;
GtkActionGroup *action_group;
DmaThreadStackTrace* current;
GList *list;
gint current_frame;
guint current_update;
GtkTreeView *treeview;
GtkMenu *menu;
GtkWidget *scrolledwindow;
};
enum {
STACK_TRACE_ACTIVE_COLUMN,
STACK_TRACE_FRAME_COLUMN,
STACK_TRACE_FILE_COLUMN,
STACK_TRACE_LINE_COLUMN,
STACK_TRACE_FUNC_COLUMN,
STACK_TRACE_ADDR_COLUMN,
STACK_TRACE_ARGS_COLUMN,
STACK_TRACE_URI_COLUMN,
STACK_TRACE_COLOR_COLUMN,
STACK_TRACE_N_COLUMNS
};
/* Helpers functions
*---------------------------------------------------------------------------*/
static gboolean
get_current_iter (GtkTreeView *view, GtkTreeIter* iter)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (view);
return gtk_tree_selection_get_selected (selection, NULL, iter);
}
/*
* returns the current stack frame or -1 on error
*/
static gint
get_current_index (StackTrace* st)
{
GtkTreeIter iter;
if (get_current_iter (st->treeview, &iter))
{
GtkTreeModel *model;
gint frame_no;
model = gtk_tree_view_get_model (st->treeview);
gtk_tree_model_get (model, &iter, STACK_TRACE_FRAME_COLUMN, &frame_no, -1);
return frame_no;
}
else
{
return -1;
}
}
static gboolean
my_gtk_tree_model_get_iter_last(GtkTreeModel *model, GtkTreeIter *last)
{
gboolean exist;
GtkTreeIter iter;
exist = gtk_tree_model_get_iter_first(model, &iter);
if (!exist) return FALSE;
do
{
*last = iter;
exist = gtk_tree_model_iter_next(model, &iter);
}
while (exist);
return TRUE;
}
static gboolean
my_gtk_tree_model_iter_prev(GtkTreeModel *model, GtkTreeIter *iter)
{
GtkTreePath* path;
gboolean exist;
path = gtk_tree_model_get_path (model, iter);
exist = gtk_tree_path_prev (path);
if (exist)
{
exist = gtk_tree_model_get_iter (model, iter, path);
}
gtk_tree_path_free (path);
return exist;
}
static gint
my_gtk_tree_iter_compare(GtkTreeModel *model, GtkTreeIter *itera, GtkTreeIter *iterb)
{
GtkTreePath* patha;
GtkTreePath* pathb;
gint comp;
patha = gtk_tree_model_get_path (model, itera);
pathb = gtk_tree_model_get_path (model, iterb);
comp = gtk_tree_path_compare (patha, pathb);
gtk_tree_path_free (patha);
gtk_tree_path_free (pathb);
return comp;
}
/* Private functions
*---------------------------------------------------------------------------*/
static void
on_clear_stack_trace (gpointer data, gpointer user_data)
{
DmaThreadStackTrace *trace = (DmaThreadStackTrace *) data;
g_object_unref (G_OBJECT (trace->model));
g_free (trace);
}
static void
dma_thread_clear_all_stack_trace (StackTrace *self)
{
/* Clear all GtkListStore */
g_list_foreach (self->list, (GFunc)on_clear_stack_trace, NULL);
g_list_free (self->list);
self->current = NULL;
self->list = NULL;
}
static void
on_stack_trace_updated (const GList *stack, gpointer user_data, GError *error)
{
StackTrace *self = (StackTrace *)user_data;
const GList *node;
GtkListStore *model;
GtkTreeIter iter;
gboolean exist;
GdkPixbuf *pic;
if (error != NULL) return;
model = GTK_LIST_STORE (self->current->model);
pic = gdk_pixbuf_new_from_file (ANJUTA_PIXMAP_POINTER, NULL);
exist = my_gtk_tree_model_get_iter_last (GTK_TREE_MODEL (model), &iter);
for (node = (const GList *)g_list_last((GList *)stack); node != NULL; node = node->prev)
{
IAnjutaDebuggerFrame *frame;
gchar *adr;
gchar *uri;
gchar *file;
frame = (IAnjutaDebuggerFrame *)node->data;
if (exist)
{
/* Check if it's the same stack frame */
gchar *adr;
gchar *args;
gulong address;
guint line;
gboolean same;
gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
STACK_TRACE_ADDR_COLUMN, &adr,
STACK_TRACE_LINE_COLUMN, &line,
STACK_TRACE_ARGS_COLUMN, &args,
-1);
address = adr != NULL ? strtoul (adr, NULL, 0) : 0;
same = (address == frame->address) && (line == frame->line);
if ((args == NULL) || (frame->args == NULL))
{
same = same && (args == frame->args);
}
else
{
same = same && (strcmp (args, frame->args) == 0);
}
g_free (adr);
g_free (args);
if (same)
{
/* Same frame, just change the color */
gtk_list_store_set (model, &iter,
STACK_TRACE_ACTIVE_COLUMN, frame->level == self->current_frame ? pic : NULL,
STACK_TRACE_FRAME_COLUMN, frame->level,
STACK_TRACE_COLOR_COLUMN, "black", -1);
/* Check previous frame */
exist = my_gtk_tree_model_iter_prev (GTK_TREE_MODEL (model), &iter);
if (!exist || (node->prev != NULL))
{
/* Last frame or Upper frame still exist */
continue;
}
/* Upper frame do not exist, remove all them */
}
/* New frame, remove all previous frame */
GtkTreeIter first;
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &first);
while (my_gtk_tree_iter_compare (GTK_TREE_MODEL (model), &first, &iter) < 0)
{
gtk_list_store_remove (model, &first);
}
gtk_list_store_remove (model, &first);
if (same)
{
break;
}
else
{
exist = FALSE;
}
}
gtk_list_store_prepend (model, &iter);
adr = g_strdup_printf ("0x%lx", frame->address);
if (frame->file)
{
if (g_path_is_absolute (frame->file))
{
GFile *gio_file = g_file_new_for_path (frame->file);
uri = g_file_get_uri (gio_file);
file = strrchr(frame->file, G_DIR_SEPARATOR) + 1;
g_object_unref (gio_file);
}
else
{
uri = NULL;
file = frame->file;
}
}
else
{
uri = NULL;
file = frame->library;
}
gtk_list_store_set(model, &iter,
STACK_TRACE_ACTIVE_COLUMN, frame->level == self->current_frame ? pic : NULL,
STACK_TRACE_FRAME_COLUMN, frame->level,
STACK_TRACE_FILE_COLUMN, file,
STACK_TRACE_LINE_COLUMN, frame->line,
STACK_TRACE_FUNC_COLUMN, frame->function,
STACK_TRACE_ADDR_COLUMN, adr,
STACK_TRACE_ARGS_COLUMN, frame->args,
STACK_TRACE_URI_COLUMN, uri,
STACK_TRACE_COLOR_COLUMN, "red",
-1);
g_free (uri);
g_free (adr);
}
g_object_unref (pic);
}
static DmaThreadStackTrace*
dma_thread_create_new_stack_trace (StackTrace *self, gint thread)
{
DmaThreadStackTrace *trace;
GtkListStore *store;
/* Create new list store */
store = gtk_list_store_new (STACK_TRACE_N_COLUMNS,
GDK_TYPE_PIXBUF,
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
trace = g_new (DmaThreadStackTrace, 1);
trace->thread = thread;
trace->model = GTK_TREE_MODEL (store);
trace->last_update = self->current_update;
self->current = trace;
/* Ask debugger to get all frame data */
dma_queue_list_frame (
self->debugger,
(IAnjutaDebuggerCallback)on_stack_trace_updated,
self);
self->list = g_list_append (self->list, trace);
return trace;
}
static DmaThreadStackTrace*
dma_thread_update_stack_trace (StackTrace *self, DmaThreadStackTrace *trace)
{
trace->last_update = self->current_update;
/* Ask debugger to get all frame data */
dma_queue_list_frame (
self->debugger,
(IAnjutaDebuggerCallback)on_stack_trace_updated,
self);
return trace;
}
static gboolean
on_find_stack_trace (gconstpointer a, gconstpointer b)
{
const DmaThreadStackTrace *trace = (const DmaThreadStackTrace *)a;
guint thread = GPOINTER_TO_UINT(b);
return trace->thread != thread;
}
static void
dma_thread_set_stack_trace (StackTrace *self, guint thread)
{
GList *list;
DmaThreadStackTrace *trace;
if ((self->current == NULL) || (self->current->thread != thread) || (self->current->last_update != self->current_update))
{
self->current_frame = 0;
list = g_list_find_custom (self->list, GINT_TO_POINTER(thread), on_find_stack_trace);
if (list == NULL)
{
/* Create new stack trace */
trace = dma_thread_create_new_stack_trace(self, thread);
}
else
{
trace = (DmaThreadStackTrace *)list->data;
self->current = trace;
if (trace->last_update != self->current_update)
{
/* Update stack trace */
dma_thread_update_stack_trace (self, trace);
}
}
gtk_tree_view_set_model (self->treeview, trace->model);
}
}
/* Callback functions
*---------------------------------------------------------------------------*/
static void
on_frame_changed (StackTrace *self, guint frame, gint thread)
{
GtkTreeIter iter;
GtkTreeModel *model;
/* Change thread */
dma_thread_set_stack_trace (self, thread);
/* Change frame */
self->current_frame = frame;
model = self->current->model;
/* Clear old pointer */
if(gtk_tree_model_get_iter_first (model, &iter))
{
do
{
/* clear pixmap on the previous active frame */
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
STACK_TRACE_ACTIVE_COLUMN, NULL, -1);
} while (gtk_tree_model_iter_next (model, &iter));
}
/* Set pointer to current frame */
if (gtk_tree_model_iter_nth_child (model, &iter, NULL, self->current_frame))
{
GdkPixbuf *pointer_pix = gdk_pixbuf_new_from_file (ANJUTA_PIXMAP_POINTER, NULL);
/* set pointer on this frame */
gtk_list_store_set (GTK_LIST_STORE(model), &iter,
STACK_TRACE_ACTIVE_COLUMN, pointer_pix,
-1);
g_object_unref (pointer_pix);
}
}
static void
on_stack_frame_set_activate (GtkAction *action, gpointer user_data)
{
StackTrace *st;
guint selected_frame;
st = (StackTrace*) user_data;
selected_frame = get_current_index (st);
/* No frame selected */
if (selected_frame == -1)
return;
/* current frame is already active */
if (selected_frame == st->current_frame)
return;
/* issue a command to switch active frame to new location */
dma_queue_set_frame (st->debugger, selected_frame);
}
static void
on_stack_view_source_activate (GtkAction *action, gpointer user_data)
{
GtkTreeModel *model;
GtkTreeSelection *selection;
GtkTreeIter iter;
GtkTreeView *view;
gchar *uri;
guint line;
gchar *adr;
gulong address;
StackTrace* st = (StackTrace*) user_data;
view = st->treeview;
selection = gtk_tree_view_get_selection (view);
if (!gtk_tree_selection_get_selected (selection, &model, &iter))
return;
/* get the frame info */
gtk_tree_model_get (model, &iter,
STACK_TRACE_URI_COLUMN, &uri,
STACK_TRACE_LINE_COLUMN, &line,
STACK_TRACE_ADDR_COLUMN, &adr,
-1);
address = adr != NULL ? strtoul (adr, NULL, 0) : 0;
g_signal_emit_by_name (st->plugin, "location-changed", address, uri, line);
g_free (uri);
g_free (adr);
}
static void
on_got_stack_trace (const gchar *trace, gpointer user_data, GError *error)
{
StackTrace* st = (StackTrace*) user_data;
IAnjutaDocumentManager *docman;
docman = anjuta_shell_get_interface (ANJUTA_PLUGIN (st->plugin)->shell, IAnjutaDocumentManager, NULL);
if (docman != NULL)
{
ianjuta_document_manager_add_buffer (docman, "Stack Trace", trace, NULL);
}
}
static void
on_stack_get_trace (GtkAction *action, gpointer user_data)
{
StackTrace* st = (StackTrace*) user_data;
/* Ask debugger to get all frame data */
dma_queue_dump_stack_trace (
st->debugger,
(IAnjutaDebuggerCallback)on_got_stack_trace,
st);
}
static void
on_stack_trace_row_activated (GtkTreeView *treeview,
GtkTreePath *arg1,
GtkTreeViewColumn *arg2,
StackTrace *st)
{
on_stack_frame_set_activate (NULL, st);
}
static gboolean
on_stack_trace_button_press (GtkWidget *widget, GdkEventButton *bevent, gpointer user_data)
{
StackTrace *st = (StackTrace*) user_data;
if ((bevent->type == GDK_BUTTON_PRESS) && (bevent->button == 3))
{
/* Right mouse click */
g_return_val_if_fail (st->menu != NULL, FALSE);
gtk_menu_popup (GTK_MENU (st->menu), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
}
else if ((bevent->type == GDK_2BUTTON_PRESS) && (bevent->button == 1))
{
/* Double left mouse click */
on_stack_view_source_activate (NULL, user_data);
}
return FALSE;
}
/* Actions table
*---------------------------------------------------------------------------*/
static GtkActionEntry actions_stack_trace[] = {
{
"ActionDmaSetCurrentFrame", /* Action name */
NULL, /* Stock icon, if any */
N_("Set current frame"), /* Display label */
NULL, /* short-cut */
NULL, /* Tooltip */
G_CALLBACK (on_stack_frame_set_activate) /* action callback */
},
{
"ActionDmaJumpToFrame",
NULL,
N_("View Source"),
NULL,
NULL,
G_CALLBACK (on_stack_view_source_activate)
},
{
"ActionDmaDumpStackTrace",
NULL,
N_("Get Stack trace"),
NULL,
NULL,
G_CALLBACK (on_stack_get_trace)
}
};
static void
create_stack_trace_gui(StackTrace *st)
{
GtkTreeModel* model;
GtkTreeSelection *selection;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
AnjutaUI *ui;
g_return_if_fail (st->scrolledwindow == NULL);
/* Create tree view */
model = GTK_TREE_MODEL(gtk_list_store_new (STACK_TRACE_N_COLUMNS,
GDK_TYPE_PIXBUF,
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_UINT,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING));
st->treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (model));
g_object_unref (G_OBJECT (model));
selection = gtk_tree_view_get_selection (st->treeview);
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
/* Columns */
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Active"));
renderer = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "pixbuf",
STACK_TRACE_ACTIVE_COLUMN);
gtk_tree_view_append_column (st->treeview, column);
gtk_tree_view_set_expander_column (st->treeview,
column);
column = gtk_tree_view_column_new ();
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Frame"));
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_FRAME_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_append_column (st->treeview, column);
gtk_tree_view_set_expander_column (st->treeview,
column);
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_FILE_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("File"));
gtk_tree_view_append_column (st->treeview, column);
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_LINE_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Line"));
gtk_tree_view_append_column (st->treeview, column);
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_FUNC_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Function"));
gtk_tree_view_append_column (st->treeview, column);
if (dma_debugger_queue_is_supported (st->debugger, HAS_MEMORY))
{
/* Display address only if debugger has such concept */
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_ADDR_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Address"));
gtk_tree_view_append_column (st->treeview, column);
}
column = gtk_tree_view_column_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_tree_view_column_pack_start (column, renderer, TRUE);
gtk_tree_view_column_add_attribute (column, renderer, "text",
STACK_TRACE_ARGS_COLUMN);
gtk_tree_view_column_add_attribute (column, renderer, "foreground",
STACK_TRACE_COLOR_COLUMN);
gtk_tree_view_column_set_sizing (column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_title (column, _("Arguments"));
gtk_tree_view_append_column (st->treeview, column);
/* Create popup menu */
ui = anjuta_shell_get_ui (ANJUTA_PLUGIN(st->plugin)->shell, NULL);
st->menu = GTK_MENU (gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui), "/PopupStack"));
/* Connect signal */
g_signal_connect (st->treeview, "button-press-event", G_CALLBACK (on_stack_trace_button_press), st);
g_signal_connect (st->treeview, "row-activated", G_CALLBACK (on_stack_trace_row_activated), st);
/* Add stack window */
st->scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (st->scrolledwindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (st->scrolledwindow),
GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (st->scrolledwindow),
GTK_WIDGET (st->treeview));
gtk_widget_show_all (st->scrolledwindow);
anjuta_shell_add_widget (ANJUTA_PLUGIN(st->plugin)->shell,
st->scrolledwindow,
"AnjutaDebuggerStack", _("Stack"),
"gdb-stack-icon", ANJUTA_SHELL_PLACEMENT_BOTTOM,
NULL);
}
static void
destroy_stack_trace_gui (StackTrace *st)
{
if (st->scrolledwindow != NULL)
{
gtk_widget_destroy (st->scrolledwindow);
st->scrolledwindow = NULL;
}
}
static void
on_program_moved (StackTrace *self, guint pid, gint thread)
{
self->current_update++;
dma_thread_set_stack_trace (self, thread);
}
static void
on_program_exited (StackTrace *self)
{
g_signal_handlers_disconnect_by_func (self->plugin, G_CALLBACK (on_program_exited), self);
g_signal_handlers_disconnect_by_func (self->plugin, G_CALLBACK (on_program_moved), self);
g_signal_handlers_disconnect_by_func (self->plugin, G_CALLBACK (on_frame_changed), self);
dma_thread_clear_all_stack_trace (self);
destroy_stack_trace_gui (self);
}
static void
on_program_started (StackTrace *self)
{
self->current_update = 0;
create_stack_trace_gui (self);
g_signal_connect_swapped (self->plugin, "program-exited", G_CALLBACK (on_program_exited), self);
g_signal_connect_swapped (self->plugin, "program-moved", G_CALLBACK (on_program_moved), self);
g_signal_connect_swapped (self->plugin, "frame-changed", G_CALLBACK (on_frame_changed), self);
}
/* Public functions
*---------------------------------------------------------------------------*/
/* Constructor & Destructor
*---------------------------------------------------------------------------*/
StackTrace *
stack_trace_new (DebugManagerPlugin *plugin)
{
StackTrace *st;
AnjutaUI *ui;
st = g_new0 (StackTrace, 1);
if (st == NULL) return NULL;
st->plugin = plugin;
st->debugger = dma_debug_manager_get_queue (plugin);
/* Register actions */
ui = anjuta_shell_get_ui (ANJUTA_PLUGIN(st->plugin)->shell, NULL);
st->action_group =
anjuta_ui_add_action_group_entries (ui, "ActionGroupStack",
_("Stack frame operations"),
actions_stack_trace,
G_N_ELEMENTS (actions_stack_trace),
GETTEXT_PACKAGE, TRUE, st);
g_signal_connect_swapped (st->plugin, "program-started", G_CALLBACK (on_program_started), st);
return st;
}
void
stack_trace_free (StackTrace * st)
{
AnjutaUI *ui;
g_return_if_fail (st != NULL);
/* Disconnect from debugger */
g_signal_handlers_disconnect_matched (st->plugin, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, st);
/* Remove menu actions */
ui = anjuta_shell_get_ui (ANJUTA_PLUGIN (st->plugin)->shell, NULL);
anjuta_ui_remove_action_group (ui, st->action_group);
/* Destroy menu */
destroy_stack_trace_gui (st);
g_free (st);
}
|