Merge lp:~ivaldi/midori/devpet-backtrace into lp:midori

Proposed by André Stösel
Status: Merged
Approved by: Cris Dywan
Approved revision: 6298
Merged at revision: 6306
Proposed branch: lp:~ivaldi/midori/devpet-backtrace
Merge into: lp:midori
Diff against target: 156 lines (+93/-2)
2 files modified
extensions/devpet.vala (+91/-2)
extensions/wscript_build (+2/-0)
To merge this branch: bzr merge lp:~ivaldi/midori/devpet-backtrace
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Paweł Forysiuk Approve
Review via email: mp+177935@code.launchpad.net

Commit message

Add backtrace support to DevPet

To post a comment you must log in.
Revision history for this message
André Stösel (ivaldi) wrote :

FYI: there is vala Linux.backtrace wrapper, but it doesn't work so I had to wrap it in sokoke

Revision history for this message
Cris Dywan (kalikiana) wrote :

Do you have any test code to see what the issue with Linux.backtrace in Vala was?

It'd be nice to use eg. addr2line or equivalent to make backtraces readable. Maybe even go the extra mile and do a little parsing to collapse duplicates and macros. But those might come in later.

review: Needs Information
Revision history for this message
André Stösel (ivaldi) wrote :

// valac bt.vala --pkg linux

void bar() {
    void* buffer[10];
    int num = Linux.backtrace (buffer, 10);
    string[] symbols = Linux.backtrace_symbols (buffer, num);

    if (symbols != null) {
        for (int i = 0; i < num; i++) {
            stdout.printf ("%s\n", symbols[i]);
        }
    } else {
        stdout.printf ("error: symbols is null\n");
    }
}

void foo() {
    bar ();
}

void main () {
    foo ();
}

PS: addr2line would be nice, indeed, but at the moment I have no time for it :/

Revision history for this message
Cris Dywan (kalikiana) wrote :

To achieve the equivalent of the C code "unowned" is needed - the problem with string[] in your snippet comes from Vala trying to memory-manage a buffer that is already owned by the stack. Also note that the buffer size is one more, same as the C code.

void* buffer[101];
int num = Linux.backtrace (buffer, 100);
unowned string[] symbols = Linux.backtrace_symbols (buffer, num);

If you change it to not use sokoke I'm happy for it to go in.

review: Needs Fixing
lp:~ivaldi/midori/devpet-backtrace updated
6298. By André Stösel

Move backtrace generation from sokoke to DevPet

Revision history for this message
André Stösel (ivaldi) wrote :

hm... I guess I overlooked this when I tested the vala part, thanks

Revision history for this message
Paweł Forysiuk (tuxator) wrote :

Looks good to me. Not sure what would be equivalent on win32 side yet.

review: Approve
Revision history for this message
Cris Dywan (kalikiana) wrote :

Nice!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/devpet.vala'
2--- extensions/devpet.vala 2013-07-30 19:43:54 +0000
3+++ extensions/devpet.vala 2013-08-02 09:19:25 +0000
4@@ -14,10 +14,58 @@
5 namespace DevPet {
6 enum TreeCells {
7 MESSAGE,
8+ BACKTRACE,
9 STOCK,
10 COUNT
11 }
12
13+ private class DataWindow : Gtk.Window {
14+ public string message {get; construct; }
15+ public string backtrace {get; construct; }
16+
17+ private void create_content () {
18+ this.title = this.message;
19+ this.set_default_size (500, 500);
20+
21+ Gtk.VBox vbox = new Gtk.VBox (false, 1);
22+ this.add (vbox);
23+
24+ Gtk.TextBuffer message_buffer = new Gtk.TextBuffer (null);
25+ message_buffer.set_text (this.message);
26+
27+ Gtk.TextView message_text_view = new Gtk.TextView.with_buffer (message_buffer);
28+ message_text_view.editable = false;
29+
30+ Gtk.TextBuffer backtrace_buffer = new Gtk.TextBuffer (null);
31+ backtrace_buffer.set_text (this.backtrace);
32+
33+ Gtk.TextView backtrace_text_view = new Gtk.TextView.with_buffer (backtrace_buffer);
34+ backtrace_text_view.editable = false;
35+
36+ Gtk.ScrolledWindow message_scroll = new Gtk.ScrolledWindow (null, null);
37+ message_scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
38+ message_scroll.add (message_text_view);
39+
40+ Gtk.ScrolledWindow backtrace_scroll = new Gtk.ScrolledWindow (null, null);
41+ backtrace_scroll.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
42+ backtrace_scroll.add (backtrace_text_view);
43+
44+ vbox.pack_start (message_scroll, false, false, 0);
45+ vbox.pack_end (backtrace_scroll, true, true, 0);
46+
47+ this.show_all ();
48+ }
49+
50+ internal DataWindow (string message, string backtrace) {
51+ GLib.Object (type: Gtk.WindowType.TOPLEVEL,
52+ window_position: Gtk.WindowPosition.CENTER,
53+ message: message,
54+ backtrace: backtrace);
55+
56+ this.create_content ();
57+ }
58+ }
59+
60 private class LogWindow : Gtk.Window {
61 private Manager manager;
62
63@@ -26,6 +74,20 @@
64 this.destroy ();
65 }
66
67+ private void row_activated (Gtk.TreePath path, Gtk.TreeViewColumn column) {
68+ Gtk.TreeIter iter;
69+ if (this.manager.list_store.get_iter (out iter, path)) {
70+ string message;
71+ string backtrace;
72+ this.manager.list_store.get(iter,
73+ TreeCells.MESSAGE, out message,
74+ TreeCells.BACKTRACE, out backtrace, -1);
75+
76+ DataWindow data_window = new DataWindow (message, backtrace);
77+ data_window.show ();
78+ }
79+ }
80+
81 private void create_content () {
82 this.title = "Midori - DevPet";
83 this.set_default_size (500, 250);
84@@ -34,6 +96,11 @@
85 Gtk.VBox vbox = new Gtk.VBox (false, 1);
86 this.add (vbox);
87
88+ #if !HAVE_WIN32
89+ Gtk.Label label = new Gtk.Label (_("Double click for more information"));
90+ vbox.pack_start (label, false, false, 0);
91+ #endif
92+
93 Gtk.ScrolledWindow scroll_windows = new Gtk.ScrolledWindow (null, null);
94 scroll_windows.set_policy (Gtk.PolicyType.NEVER , Gtk.PolicyType.AUTOMATIC);
95 scroll_windows.set_shadow_type (Gtk.ShadowType.ETCHED_IN);
96@@ -56,6 +123,10 @@
97 -1, "Message",
98 new Gtk.CellRendererText (), "text", TreeCells.MESSAGE);
99
100+ #if !HAVE_WIN32
101+ treeview.row_activated.connect (this.row_activated);
102+ #endif
103+
104 this.show_all ();
105 }
106
107@@ -103,8 +174,26 @@
108 this.trayicon.set_from_stock (stock);
109 }
110
111+ #if !HAVE_WIN32
112+ string bt = "";
113+ void* buffer[100];
114+ int num = Linux.backtrace (buffer, 100);
115+ unowned string[] symbols = Linux.backtrace_symbols (buffer, num);
116+ if (symbols != null) {
117+ /* we don't need the first three lines */
118+ for (int i = 3; i < num; i++) {
119+ bt += "\r\n%s".printf(symbols[i]);
120+ }
121+ }
122+ #endif
123+
124 this.list_store.append (out iter);
125- this.list_store.set (iter, TreeCells.MESSAGE, message, TreeCells.STOCK, theme.load_icon (stock, 16, 0));
126+ this.list_store.set (iter,
127+ TreeCells.MESSAGE, message,
128+ #if !HAVE_WIN32
129+ TreeCells.BACKTRACE, bt,
130+ #endif
131+ TreeCells.STOCK, theme.load_icon (stock, 16, 0));
132
133 this.trayicon.set_visible (true);
134 }
135@@ -143,7 +232,7 @@
136 this.trayicon.set_tooltip_text ("Midori - DevPet");
137 this.trayicon.activate.connect(this.show_error_log);
138
139- this.list_store = new Gtk.ListStore (TreeCells.COUNT, typeof(string), typeof (Gdk.Pixbuf));
140+ this.list_store = new Gtk.ListStore (TreeCells.COUNT, typeof(string), typeof(string), typeof (Gdk.Pixbuf));
141
142 this.activate.connect (this.activated);
143 this.deactivate.connect (this.deactivated);
144
145=== modified file 'extensions/wscript_build'
146--- extensions/wscript_build 2013-07-31 20:27:52 +0000
147+++ extensions/wscript_build 2013-08-02 09:19:25 +0000
148@@ -54,6 +54,8 @@
149 obj.packages += ' webkitgtk-3.0'
150 if bld.env['HAVE_GRANITE']:
151 obj.packages += ' granite'
152+ if bld.env['platform'] != 'win32':
153+ obj.packages += ' linux'
154 obj.install_path = '${LIBDIR}/midori'
155 # See LINKFLAGS in wscript: w/ o it we get several "undefined reference" errors
156 if bld.env['platform'] == 'win32':

Subscribers

People subscribed via source and target branches

to all changes: