~ubuntu-core-dev/ubuntu/jammy/apport/ubuntu

« back to all changes in this revision

Viewing changes to bin/java_uncaught_exception

  • Committer: Matt Zimmerman
  • Date: 2010-03-26 17:49:17 UTC
  • mto: (1369.34.24 trunk)
  • mto: This revision was merged to the branch mainline in revision 1713.
  • Revision ID: mdz@ubuntu.com-20100326174917-o9m4nkkhkwlh5yof
Initial implementation of Java crash handling

java/.../ApportUncaughtExceptionHandler.java - Java exception handler
bin/java_uncaught_exception - invoked to create Java problem reports
test/crash.java - program to test Java crashes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import sys
 
4
 
 
5
#from apport import unicode_gettext as _
 
6
 
 
7
def make_title(report):
 
8
        lines = report['StackTrace'].split('\n')
 
9
        message = lines[0].strip()
 
10
        stackframe = lines[1].strip()
 
11
        return '%s in %s' % (message, stackframe)
 
12
 
 
13
def main():
 
14
        from apport.packaging_impl import impl as packaging
 
15
        if not packaging.enabled():
 
16
                return -1
 
17
 
 
18
        # read from the JVM process a sequence of key, value delimited by null
 
19
        # bytes
 
20
        items = sys.stdin.read().split('\0')
 
21
        d = dict()
 
22
        while items:
 
23
                key = items.pop(0)
 
24
                if not items: break
 
25
                value = items.pop(0)
 
26
                d[key] = value
 
27
                
 
28
        log = open('/tmp/log', 'w')
 
29
        log.write(`d`)
 
30
 
 
31
        # create report
 
32
        import apport.report
 
33
        import os
 
34
 
 
35
        report = apport.report.Report(type='Crash')
 
36
        # assume our parent is the JVM process
 
37
        report.pid = os.getppid()
 
38
 
 
39
        report.add_os_info()
 
40
        report.add_proc_info()
 
41
        # these aren't relevant because the crash was in bytecode
 
42
        del report['ProcMaps']
 
43
        del report['ProcStatus']
 
44
        report.add_user_info()
 
45
 
 
46
        # add in data which was fed to us from the JVM process
 
47
        for key, value in d.items():
 
48
                report[key] = value
 
49
 
 
50
        if 'MainClassUrl' in report:
 
51
                import urlparse
 
52
                url = report['MainClassUrl']
 
53
                scheme, netloc, path, params, query, fragment = urlparse.urlparse(url)
 
54
 
 
55
                if scheme == 'file':
 
56
                        if '!/' in path:
 
57
                                # jar
 
58
                                report['ExecutablePath'] = path.split('!/', 1)
 
59
                        else:
 
60
                                report['ExecutablePath'] = path
 
61
 
 
62
        report['Title'] = make_title(report)
 
63
 
 
64
        report.write(open(apport.fileutils.make_report_path(report), 'w'))
 
65
 
 
66
if __name__ == '__main__':
 
67
        main()