Merge lp:~darkxst/apport/sandbox-autoload into lp:apport

Proposed by Tim Lunn
Status: Needs review
Proposed branch: lp:~darkxst/apport/sandbox-autoload
Merge into: lp:apport
Diff against target: 68 lines (+23/-2)
2 files modified
apport/report.py (+22/-2)
bin/apport-retrace (+1/-0)
To merge this branch: bzr merge lp:~darkxst/apport/sandbox-autoload
Reviewer Review Type Date Requested Status
Martin Pitt (community) Needs Information
Review via email: mp+252686@code.launchpad.net

Description of the change

This is mostly useful for glib based apps to get the pretty printers working, which gives improved output on gobjects and signals. Though there are a few other packages that ship them as well.

apport-retrace when run against the system filesystem would already pick up these scripts.

To post a comment you must log in.
Martin Pitt (pitti) wrote :

Very nice, thanks! Will that append to the default search path, or completely replace it? https://sourceware.org/gdb/onlinedocs/gdb/objfile_002dgdbdotext-file.html#set%20auto-load%20scripts-directory doesn't really tell.. We certainly do want to keep gdb's scripts on the host, just additionally load the ones in the sandbox.

review: Needs Information
Tim Lunn (darkxst) wrote :

It currently replaces the search path, which seems fine to me since the scripts are always versioned with soname, so doesnt make sense to load them from the host. (actually thats not entirely true, python has a wrapper for the binary which obviously not versioned.)

auto-load: Attempted file "/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.gdb" does not exist.
auto-load: Attempted file "sandbox/usr/share/gdb/auto-load/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.gdb" does not exist.
auto-load: Attempted file "/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" does not exist.
auto-load: Attempted file "sandbox/usr/share/gdb/auto-load/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" exists.
auto-load: Loading python script "sandbox/usr/share/gdb/auto-load/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" by extension for objfile "/lib/x86_64-linux-gnu/libglib-2.0.so.0".
auto-load: Matching file "sandbox/usr/share/gdb/auto-load/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" to pattern "sandbox/usr/share/gdb/auto-load"
auto-load: File "sandbox/usr/share/gdb/auto-load/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" matches directory "sandbox/usr/share/gdb/auto-load".

The default search path is
(gdb) show auto-load scripts-directory
List of directories from which to load auto-loaded scripts is $debugdir:$datadir/auto-load

So could use the following to append to the default search paths
set auto-load scripts-directory $debugdir:$datadir/auto-load:sandbox/$debugdir:sandbox/$datadir/auto-load

lp:~darkxst/apport/sandbox-autoload updated
2931. By Tim Lunn on 2015-03-12

search both host and sandbox for scripts

Tim Lunn (darkxst) wrote :

actually the solib prefix gets inserted in the path, so we will never match a script on the system $debugdir is already sandbox-ified. we also need to insert a symlink into the sandbox so the path can match

auto-load: Attempted file "/tmp/apport_sandbox_74lv3Y//usr/share/gdb/auto-load/tmp/apport_sandbox_74lv3Y/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py" exists.

lp:~darkxst/apport/sandbox-autoload updated
2932. By Tim Lunn on 2015-03-13

clean up search path and insert a symlinnk into the sandbox so we match full solib path

Tim Lunn (darkxst) wrote :

This is better:
$ apport-retrace -g -S config /var/crash/_usr_bin_gjs-console.1000.crash
(gdb) info auto-load python-scripts
Loaded Script
Yes /tmp/apport_sandbox_eMbqCa//usr/share/gdb/auto-load/tmp/apport_sandbox_eMbqCa/lib/x86_64-linux-gnu/libglib-2.0.so.0.4391.0-gdb.py
Yes /tmp/apport_sandbox_eMbqCa//usr/share/gdb/auto-load/tmp/apport_sandbox_eMbqCa/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4391.0-gdb.py
Yes /tmp/apport_sandbox_eMbqCa//usr/share/gdb/auto-load/tmp/apport_sandbox_eMbqCa/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20-gdb.py

Unmerged revisions

2932. By Tim Lunn on 2015-03-13

clean up search path and insert a symlinnk into the sandbox so we match full solib path

2931. By Tim Lunn on 2015-03-12

search both host and sandbox for scripts

2930. By Tim Lunn on 2015-03-12

use sandbox for gdb auto-load scripts

This allows for the pretty printers to work

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apport/report.py'
2--- apport/report.py 2015-02-10 10:21:40 +0000
3+++ apport/report.py 2015-03-13 02:05:48 +0000
4@@ -9,7 +9,7 @@
5 # option) any later version. See http://www.gnu.org/copyleft/gpl.html for
6 # the full text of the license.
7
8-import subprocess, tempfile, os.path, re, pwd, grp, os, time
9+import subprocess, tempfile, os.path, re, pwd, grp, os, time, shutil
10 import fnmatch, glob, traceback, errno, sys, atexit, locale
11
12 import xml.dom, xml.dom.minidom
13@@ -688,6 +688,7 @@
14 # call gdb
15 try:
16 out = _command_output(gdb_cmd).decode('UTF-8', errors='replace')
17+ self.autoload_clean(rootdir)
18 except OSError:
19 return
20
21@@ -1461,6 +1462,21 @@
22 else:
23 self[k] = pattern.sub(repl, self[k])
24
25+ def autoload_links(self, sandbox):
26+ rel_sandbox = sandbox.lstrip(os.path.sep)
27+ base = rel_sandbox.rsplit(os.path.sep,1)[0]
28+ autoload_path = os.path.join(sandbox, 'usr', 'share', 'gdb', 'auto-load')
29+ base_path = os.path.join(autoload_path, base)
30+ if not os.path.exists(base_path) and len(base) > 1:
31+ os.makedirs(base_path)
32+ if not os.path.exists(os.path.join(autoload_path, rel_sandbox)):
33+ os.symlink(autoload_path, os.path.join(autoload_path, rel_sandbox))
34+
35+ def autoload_clean(self,sandbox):
36+ if sandbox:
37+ rel_sandbox = sandbox.lstrip('/')
38+ shutil.rmtree(os.path.join(sandbox, 'usr', 'share', 'gdb', 'auto-load', rel_sandbox.split(os.path.sep)[0]))
39+
40 def gdb_command(self, sandbox):
41 '''Build gdb command for this report.
42
43@@ -1501,8 +1517,12 @@
44 # note, i386 vs. x86_64 is auto-detected just fine
45
46 if sandbox:
47+ self.autoload_links(sandbox)
48+ scripts_path = '$debugdir:%s/$datadir/auto-load' % sandbox
49 command += ['--ex', 'set debug-file-directory %s/usr/lib/debug' % sandbox,
50- '--ex', 'set solib-absolute-prefix ' + sandbox]
51+ '--ex', 'set solib-absolute-prefix ' + sandbox,
52+ '--ex', 'set auto-load scripts-directory ' + scripts_path,
53+ '--ex', 'set auto-load safe-path ' + scripts_path]
54 executable = sandbox + '/' + executable
55
56 assert os.path.exists(executable)
57
58=== modified file 'bin/apport-retrace'
59--- bin/apport-retrace 2014-08-29 10:32:33 +0000
60+++ bin/apport-retrace 2015-03-13 02:05:48 +0000
61@@ -316,6 +316,7 @@
62 apport.log('Calling gdb command: ' + cmd, log_timestamps)
63 apport.memdbg('before calling gdb')
64 subprocess.call(gdb_cmd)
65+ report.autoload_clean(sandbox)
66 else:
67 # regenerate gdb info
68 apport.memdbg('before collecting gdb info')

Subscribers

People subscribed via source and target branches