ó
ýGpNc           @   s·  d  d l  Z  d  d l Z d  d l Z d e f d „  ƒ  YZ d „  Z e d k r³e e  j ƒ d k oz e  j d d d	 g k r§ d
 GHd GHd e  j d GHe  j	 d ƒ nÿ e e  j ƒ d k rQe e
 e  j d ƒ j ƒ  e
 e  j d ƒ j ƒ  e
 e  j d ƒ j ƒ  ƒ Z e j ƒ  \ Z Z Z d e e f GHd Z e rAd Z n  e  j	 e ƒ nU d  d l Z d  d l Z d  d l  Z  d Z d Z d Z d Z d e j f d „  ƒ  YZ e j ƒ  n  d S(   iÿÿÿÿNt	   ParseSegvc           B   s\   e  Z e d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   c         C   s¼   | r t  j d t  j ƒ n  |  j | ƒ |  _ d  |  _ x6 d d g D]( } | |  j k rD |  j | |  _ qD qD W|  j | ƒ \ |  _ |  _	 |  _
 |  _ |  _ d  |  _ |  j | ƒ |  _ d  S(   Nt   levelt   rspt   esp(   t   loggingt   basicConfigt   DEBUGt
   parse_regst   regst   Nonet   spt   parse_disassemblyt   linet   pct   insnt   srct   destt	   stack_vmat
   parse_mapst   maps(   t   selft	   registerst   disassemblyR   t   debugt   reg(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   __init__   s    	-	c         C   s<   x5 |  j  D]* } | | d k r
 | | d k  r
 | Sq
 Wd  S(   Nt   startt   end(   R   R	   (   R   t   addrt   vma(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   find_vma"   s     c         C   s#  g  } x| j  ƒ  D]} | j ƒ  j ƒ  } y | d d !\ } } } } Wn t d | j ƒ  ƒ ‚ n Xt | ƒ d k rƒ d  }	 n
 | d }	 g  | j d ƒ D] }
 t |
 d ƒ ^ q \ } } |	 d k rÜ t | ƒ |  _ n  | j i | d 6| d	 6| d
 6|	 d 6ƒ t	 j
 | | | |	 ƒ q W| S(   Ni    i   s   Cannot parse maps line: %si   t   -i   s   [stack]R   R   t   permst   name(   t
   splitlinest   stript   splitt
   ValueErrort   lenR	   t   intR   t   appendR   R   (   R   t   maps_strR   R   t   itemst   spanR    t   bitst   devR!   t   xR   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyR   (   s     	
1)c         C   sg   t  ƒ  } xW | j ƒ  D]I } | j ƒ  d d !\ } } t | d ƒ | | <t j d | | | ƒ q W| S(   Ni    i   i   s	   %s:0x%08x(   t   dictR"   R$   R'   R   R   (   R   t   reg_strR   R   R   t   hexvalue(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyR   ;   s    	c         C   s  |  j  s t d ƒ ‚ n  | j ƒ  } t | ƒ d k rY | d j d ƒ rY | j d ƒ n  t | ƒ d k  rz t d ƒ ‚ n  | d j ƒ  } | j d ƒ r¬ | d j ƒ  } n  t j | ƒ | j	 ƒ  d } | j d ƒ r÷ t
 | j	 d	 ƒ d d
 ƒ } n t d | | f ƒ ‚ t j d | ƒ | j	 d	 d ƒ d j ƒ  } d | k sc| d k rvt | ƒ d k rv| | d  d  d  f S| d k rÌ| d j d ƒ rÌ| d | d j ƒ  } | j	 d	 d ƒ d j ƒ  } n  | j	 ƒ  } | d j d ƒ r| d j d ƒ r| j d ƒ n  d } t | ƒ d k r8| j d ƒ } n  d j | ƒ }	 t j d |	 ƒ g  }
 d  } d  } | d k r~d  }
 n¹ t j d | ƒ xH t j d | ƒ D]4 } t | j d ƒ ƒ r¡|
 j | j d ƒ ƒ q¡q¡Wt |
 ƒ d k r|
 d } t j d | ƒ n  t |
 ƒ d k r7|
 d } t j d | ƒ n  |	 d# k rzx4 d  d! g D]# } | |  j  k rPd" | } PqPqPWn  | | |	 | | f S($   Ns   Registers not loaded yet!?i    t   Dumpi   s    Failed to load empty disassemblys   =>i   t   0xt   :i   s1   Could not parse PC "%s" from disassembly line: %ss
   pc: 0x%08xs   Cannot access memory at addresst    t    iÿÿÿÿt   >t   <s   insn: %ss
   args: "%s"s   ([^,\(]*(\(:?[^\)]+\))*)s   src: %ss   dest: %st   pusht   popt   pushlt   poplt   callt   callqt   rett   retqR   R   s   (%%%s)(   R9   s   popR;   R<   s   callR>   R?   R@   (   R   R%   R"   R&   t
   startswithR:   R#   R   R   R$   R'   R	   t   endswitht   joint   ret   finditert   groupR(   (   R   R   t   linesR   t   pc_strR   t   full_insn_strt
   insn_partst   args_strR   t   argsR   R   t   mR   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyR   C   sf    	%*&	


c      
   C   s_  i d d g d 6d d g d 6d d g d	 6} |  j  | ƒ } | d  k r— d
 } | d k  rc d } n  t d | | | | d f d | | d | f f S| | d k r8d } | d k rÛ d	 | d k rÒ d } qÛ d } n  d | | d | | d f } t d | | | | d | d | d | d | d f | f St d | | f d | | d f Sd  S(   Nt
   executablet	   executingR.   t   readablet   readingt   rt   writablet   writingt   wt   unknowni   t   NULLsA   %s (0x%08x) not located in a known VMA region (needed %s region)!i    s	   %s %s VMAi   R    R5   s	   writable s   non-writable s   %s %sVMA %sR!   s5   %s (0x%08x) in non-%s VMA region: 0x%08x-0x%08x %s %sR   R   s   %s (0x%08x) oks   %s ok(   R   R	   t   Falset   True(   R   t   permR   R!   t	   perm_nameR   t   alarmistt   short(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   validate_vmaŠ   s     -	4		>c         C   sc  | } d } | j  d ƒ r( | d } n  | |  j k rB |  j | St | ƒ d k r~ | j d ƒ r~ | d O} d | d } n  | |  j k r |  j | | @St | ƒ d k rÕ | j d ƒ rÕ | d	 O} d
 | } n  | |  j k rô |  j | | @St | ƒ d k r0| j  d ƒ r0| d O} d | d } n  | |  j k rO|  j | | @St d | ƒ ‚ d  S(   Ni    t   %i   i   t   li ÿ  s   %sxR.   l     þ s   e%si   t   el       üÿ s   r%ss   Could not resolve register '%s'(   RA   R   R&   RB   R%   (   R   R   t   reg_origt   mask(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   register_valueŸ   s,    !
!
!
c         C   sF  d } | j  d ƒ rU d | k rU | j d d ƒ } |  j | d d } | d } n  | j d ƒ } | d } d } | j  d ƒ r– d } | d } n  | j  d ƒ r² | d } n  t | ƒ d k r'| j  d ƒ rç |  j | d } q-| j  d	 ƒ st d
 | d ƒ ‚ n  t | d d ƒ | } n d } d d „ } d } t | ƒ d k r| d d d !}	 |	 j d ƒ }
 d } t |
 ƒ d k r¢| |  |
 d | ƒ } n  d } t |
 ƒ d k rÓ| |  |
 d | ƒ } n  d } t |
 ƒ d k r| |  |
 d | ƒ } n  | | | } n  | | | } d |  j k r:| d S| d Sd  S(   Ni    R_   R4   i   t   (R   iÿÿÿÿt   *R3   s   Unknown offset literal: %si   i   c         S   sH   | j  d ƒ r# |  j | d } n! | d k r8 d } n t | ƒ } | S(   NR_   i   R5   i    (   RA   R   R'   (   R   t   textt   val(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   _reg_valâ   s    	t   ,R   l        l            (   RA   R$   R   R&   R%   R'   (   R   t   argt   segmentt   partst   offsett   signt   addRi   t   valuet   parenst   reg_listt   baset   indext   scale(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   calculate_argÄ   sN    

c   	   
   C   sª  t  } g  } d |  j g } |  j d |  j d ƒ \ } } } | j | ƒ | sf | j | ƒ t } n  |  j d! k rŒ | j d |  j ƒ n]|  j rDd |  j k rá |  j d d" k rá |  j j d ƒ rá | j d |  j ƒ qD|  j	 |  j ƒ } |  j d | d |  j ƒ \ } } } | j | ƒ | sD| j | ƒ t } qDn  |  j
 réd |  j
 k r†|  j
 d d# k r†| j d |  j
 ƒ qé|  j	 |  j
 ƒ } |  j d | d |  j
 ƒ \ } } } | j | ƒ | sé| j | ƒ t } qén  |  j d$ k rB| rB| j d |  j |  j ƒ ƒ | j d |  j |  j ƒ ƒ t } n  |  j d  k r|  j d  k r½|  j |  j |  j d k  r| j d ƒ n  |  j |  j |  j d k r½| j d ƒ q½n  | s|  j d |  j d ƒ \ } } } | j | ƒ | s| j | ƒ t } qqn  | s‹|  j |  j ƒ } | rn| d d k sQ| d d k rn| j d ƒ | j d ƒ q‹| j d ƒ | j d ƒ n  | d  j | ƒ d  j | ƒ f S(%   Ns   Segfault happened at: %sR.   t   PCt   leat   leals   insn (%s) does not access VMAR4   i    R_   t   $Rf   s   *%s   source "%s" okRR   s   source "%s"s   destination "%s" okRU   s   destination "%s"t   outt   ins(   disallowed I/O port operation on port %dR   s/   Stack memory exhausted (SP below stack segment)R   s&   Stack pointer not within stack segmentt   SPR!   s   [vdso]s
   [vsyscall]sS   Reason could not be automatically determined. (Unhandled exception in kernel code?)s-   Reason could not be automatically determined.s   
(   Ry   Rz   (   R_   R{   Rf   (   R_   R{   Rf   (   s   outs   in(   RX   R   R^   R   R(   RY   R   R   RA   Rw   R   Rd   R
   R	   R   R   R   RC   (	   R   t
   understoodt   reasont   detailst   validR|   R]   R   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   report  sh    !		5%	"%	!&(   t   __name__t
   __module__RX   R   R   R   R   R   R^   Rd   Rw   Rƒ   (    (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyR       s   				G		%	@c         C   sù   |  j  d d ƒ d k r d  Sd d d d d g } x/ | D]' } |  j | ƒ s8 d | |  d	 <d  Sq8 W|  d d k rw d  SyT t |  d |  d |  d ƒ } | j ƒ  \ } } } | rÀ | |  d <n  | |  d	 <Wn' t k
 rô } d t | ƒ |  d	 <n Xd  S(   Nt   Signalt   0t   11t   Architecturet   Disassemblyt   ProcMapst	   Registerss$   Skipped: missing required field "%s"t   SegvAnalysist   i386t   amd64t
   SegvReasons   Failure: %s(   s   i386s   amd64(   t   gett   has_keyR    Rƒ   t   BaseExceptiont   str(   Rƒ   t   neededt   fieldt   segvR   R€   R   Ra   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   add_infoK  s"    t   __main__i   i   s   -hs   --helps8   To run self-test, run without any arguments (or with -v)s    To do stand-alone crash parsing:s6     Usage: %s Registers.txt Disassembly.txt ProcMaps.txti    i   i   s   %s

%ssú  eax            0xffffffff -1
ecx            0xbfc6af40   -1077498048
edx            0x1  1
ebx            0x26eff4 2551796
esp            0xbfc6af24   0xbfc6af24
ebp            0xbfc6af28   0xbfc6af28
esi            0x826bb60    136756064
edi            0x8083480    134755456
eip            0x808354e    0x808354e <main+14>
eflags         0x200286 [ PF SF IF ID ]
cs             0x73 115
ss             0x7b 123
ds             0x7b 123
es             0x7b 123
fs             0x4  4
gs             0x33 51
s-  rax            0xffffffffffffffff   -1
rbx            0x26eff4 2551796
rcx            0xffffffffffffffff   -1
rdx            0xffffffffff600180   -10485376
rsi            0x0  0
rdi            0x7fffffffe3b0   140737488348080
rbp            0x0  0x0
rsp            0x0000bfc6af24   0x0000bfc6af24
r8             0x0  0
r9             0x0  0
r10            0x7fffffffe140   140737488347456
r11            0x246    582
r12            0x7fffffffe400   140737488348160
r13            0x7fffffffe468   140737488348264
r14            0x1  1
r15            0x7fffffffe460   140737488348256
rip            0x7ffff790be10   0x7ffff790be10 <nanosleep+16>
eflags         0x246    [ PF ZF IF ]
cs             0x33 51
ss             0x2b 43
ds             0x0  0
es             0x0  0
fs             0x0  0
gs             0x0  0
fctrl          0x37f    895
fstat          0x0  0
ftag           0xffff   65535
fiseg          0x0  0
fioff          0x40303a 4206650
foseg          0x0  0
fooff          0x0  0
fop            0x5d8    1496
mxcsr          0x1f80   [ IM DM ZM OM UM PM ]
sæ	  00110000-0026c000 r-xp 00000000 08:06 375131     /lib/tls/i686/cmov/libc-2.9.so
0026c000-0026d000 ---p 0015c000 08:06 375131     /lib/tls/i686/cmov/libc-2.9.so
0026d000-0026f000 r--p 0015c000 08:06 375131     /lib/tls/i686/cmov/libc-2.9.so
0026f000-00270000 rw-p 0015e000 08:06 375131     /lib/tls/i686/cmov/libc-2.9.so
00270000-00273000 rw-p 00000000 00:00 0 
002c1000-002e5000 r-xp 00000000 08:06 375135     /lib/tls/i686/cmov/libm-2.9.so
002e5000-002e6000 r--p 00023000 08:06 375135     /lib/tls/i686/cmov/libm-2.9.so
002e6000-002e7000 rw-p 00024000 08:06 375135     /lib/tls/i686/cmov/libm-2.9.so
00318000-00334000 r-xp 00000000 08:06 977846     /lib/ld-2.9.so
00334000-00335000 r--p 0001b000 08:06 977846     /lib/ld-2.9.so
00335000-00336000 rw-p 0001c000 08:06 977846     /lib/ld-2.9.so
0056e000-005a1000 r-xp 00000000 08:06 65575      /lib/libncurses.so.5.7
005a1000-005a3000 r--p 00033000 08:06 65575      /lib/libncurses.so.5.7
005a3000-005a4000 rw-p 00035000 08:06 65575      /lib/libncurses.so.5.7
00b67000-00b68000 r-xp 00000000 00:00 0          [vdso]
00bb6000-00bcb000 r-xp 00000000 08:06 375202     /lib/tls/i686/cmov/libpthread-2.9.so
00bcb000-00bcc000 r--p 00014000 08:06 375202     /lib/tls/i686/cmov/libpthread-2.9.so
00bcc000-00bcd000 rw-p 00015000 08:06 375202     /lib/tls/i686/cmov/libpthread-2.9.so
00bcd000-00bcf000 rw-p 00000000 00:00 0 
00beb000-00bed000 r-xp 00000000 08:06 375134     /lib/tls/i686/cmov/libdl-2.9.so
00bed000-00bee000 r--p 00001000 08:06 375134     /lib/tls/i686/cmov/libdl-2.9.so
00bee000-00bef000 rw-p 00002000 08:06 375134     /lib/tls/i686/cmov/libdl-2.9.so
00c56000-00c7a000 r-xp 00000000 08:06 1140420    /usr/lib/libexpat.so.1.5.2
00c7a000-00c7c000 r--p 00023000 08:06 1140420    /usr/lib/libexpat.so.1.5.2
00c7c000-00c7d000 rw-p 00025000 08:06 1140420    /usr/lib/libexpat.so.1.5.2
00dce000-00dfa000 r-xp 00000000 08:06 65612      /lib/libreadline.so.5.2
00dfa000-00dfb000 ---p 0002c000 08:06 65612      /lib/libreadline.so.5.2
00dfb000-00dfc000 r--p 0002c000 08:06 65612      /lib/libreadline.so.5.2
00dfc000-00dff000 rw-p 0002d000 08:06 65612      /lib/libreadline.so.5.2
00dff000-00e00000 rw-p 00000000 00:00 0 
08048000-0831c000 r-xp 00000000 08:06 1140349    /usr/bin/gdb
0831c000-0831d000 r--p 002d3000 08:06 1140349    /usr/bin/gdb
0831d000-08325000 rw-p 002d4000 08:06 1140349    /usr/bin/gdb
08325000-0833f000 rw-p 00000000 00:00 0 
b8077000-b807a000 rw-p 00000000 00:00 0 
b8096000-b8098000 rw-p 00000000 00:00 0 
bfc57000-bfc6c000 rw-p 00000000 00:00 0          [stack]
s  0x08083540 <main+0>:    lea    0x4(%esp),%ecx
0x08083544 <main+4>:    and    $0xfffffff0,%esp
0x08083547 <main+7>:    pushl  -0x4(%ecx)
0x0808354a <main+10>:   push   %ebp
0x0808354b <main+11>:   mov    %esp,%ebp
0x0808354d <main+13>:   push   %ecx
0x0808354e <main+14>:   sub    $0x14,%esp
0x08083551 <main+17>:   mov    (%ecx),%eax
0x08083553 <main+19>:   mov    0x4(%ecx),%edx
0x08083556 <main+22>:   lea    -0x14(%ebp),%ecx
0x08083559 <main+25>:   movl   $0x0,-0xc(%ebp)
0x08083560 <main+32>:   movl   $0x826bc68,-0x8(%ebp)
0x08083567 <main+39>:   mov    %eax,-0x14(%ebp)
0x0808356a <main+42>:   mov    %edx,-0x10(%ebp)
0x0808356d <main+45>:   mov    %ecx,(%esp)
0x08083570 <main+48>:   call   0x8083580 <gdb_main>
0x08083575 <main+53>:   add    $0x14,%esp
0x08083578 <main+56>:   pop    %ecx
0x08083579 <main+57>:   pop    %ebp
0x0808357a <main+58>:   lea    -0x4(%ecx),%esp
0x0808357d <main+61>:   ret    
t   _Tc           B   sÔ   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   Test Segfault Parserc         C   s   d S(   s$   Set up prior to each test_* functionN(    (   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   setUpì  s    c         C   s   d S(   s#   Clean up after each test_* functionN(    (   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   tearDownï  s    c         C   sÈ   d } |  j  t t | d d ƒ y t | d d ƒ } Wn5 t k
 rl } |  j d t | ƒ k t | ƒ ƒ n Xd } d } t | | d ƒ } |  j | j d d | ƒ d | _ |  j  t | j d ƒ d S(	   s   Require valid registerss   a 0x10
b !!!
R5   s   invalid literal for int()s   a 0x10s.   0x08083540 <main+0>:    lea    0x4(%esp),%ecx
t   ai   N(	   t   assertRaisesR%   R    t
   assertTrueR”   t   assertEqualsR   R	   R   (   R   R   R—   Ra   t   disasm(    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_invalid_00_registersò  s    &	c         C   sÞ  d } d } |  j  t t | | d ƒ d } |  j  t t | | d ƒ d } |  j  t t | | d ƒ d } |  j  t t | | d ƒ d } t | | d ƒ } |  j | j d | j ƒ |  j | j d3 | j ƒ |  j | j d3 | j ƒ |  j | j d3 | j ƒ d } t | | d ƒ } |  j | j d	 | j ƒ |  j | j d3 | j ƒ |  j | j d3 | j ƒ |  j | j d3 | j ƒ d
 } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ d } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d3 | j ƒ d } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d3 | j ƒ d } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ d } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ d } t | | d ƒ } |  j | j d  | j ƒ |  j | j d! | j ƒ |  j | j d" | j ƒ |  j | j d# | j ƒ d$ } t | | d ƒ } |  j | j d% | j ƒ |  j | j d& | j ƒ |  j | j d' | j ƒ |  j | j d( | j ƒ d) } t | | d ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ d* } t | | d ƒ } |  j | j d+ | j ƒ |  j | j d, | j ƒ |  j | j d3 | j ƒ |  j | j d3 | j ƒ d- } d. } t | | d ƒ } |  j | j d/ | j ƒ |  j | j d0 | j ƒ |  j | j d | j ƒ |  j | j d1 | j ƒ d- } d2 } t | | d ƒ } |  j | j d/ | j ƒ |  j | j d0 | j ƒ |  j | j d | j ƒ |  j | j d1 | j ƒ d3 S(4   s   Require valid disassemblys   a 0x10R5   s   Dump ...s   Dump ...
monkeyt   monkeys;   0x1111111111: Cannot access memory at address 0x1111111111
l   ""D s   0x2111111111: 
l   ""„ s8   0x8069ff0 <fopen@plt+132220>: cmpb   $0x0,(%eax,%ebx,1)
iðŸt   cmpbs   $0x0s   (%eax,%ebx,1)s-   0xb765bb48 <_XSend+440>:  call   *0x40(%edi)
l   H;Ën R=   s   *0x40(%edi)s;   0xb7aae5a0:   call   0xb7a805af <_Unwind_Find_FDE@plt+111>
l    eUo t
   0xb7a805afs)   0x09083540:    mov    0x4(%esp),%es:%ecx
i@5	t   movs	   0x4(%esp)s   %es:%ecxs.   0x08083540 <main+0>:    lea    0x4(%esp),%ecx
i@5Ry   s   %ecxsT   0x404127 <exo_mount_hal_device_mount+167>:    
    repz cmpsb %es:(%rdi),%ds:(%rsi)
i'A@ s
   repz cmpsbs
   %es:(%rdi)s
   %ds:(%rsi)s1   0xb031765a <hufftab16+570>: add    0x3430433,%eaxl   Zvb` Rp   t	   0x3430433s   %eaxs7   Dump ...
0x08083540 <main+0>:    lea    0x4(%esp),%ecx
s   0x08083550 <main+0>:    nop
iP5t   nops	   esp 0x444s"   0x08083560 <main+0>:    push %ecx
i`5R9   s   (%esp)s%   => 0x08083560 <main+0>:    push %ecx
N(	   Rž   R%   R    R    R   R   R	   R   R   (   R   R   R¡   R—   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_invalid_01_disassembly  s²    c         C   sÇ   d } d } d } t  | | | ƒ } |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ |  j | j d | j ƒ | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ d	 S(
   s   I/O port violationss   rax            0x3  3sR   0x4087f1 <snd_pcm_hw_params_set_channels_near@plt+19345>:   
    out    %al,$0xb3
s  00400000-00412000 r-xp 00000000 08:04 10371157                           /usr/sbin/pommed
00611000-00614000 rw-p 00011000 08:04 10371157                           /usr/sbin/pommed
00614000-00635000 rw-p 00614000 00:00 0                                  [heap]
iñ‡@ R|   s   %als   $0xb3s'   disallowed I/O port operation on port 3N(   R    R    R   R   R   R   Rƒ   RŸ   (   R   R   R¡   R   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_ioport_operations  s    c         C   s¯  d } d } d } |  j  t t | | | ƒ d } t | | | ƒ } |  j | j d d d | ƒ |  j | j d d d	 | ƒ |  j | j d d
 d | ƒ |  j | j d d d | ƒ |  j | j d d d | ƒ |  j | j d d d | ƒ |  j | j d d
 d | ƒ |  j | j d d d | ƒ |  j | j d d d | ƒ |  j | j d d d | ƒ |  j | j d d
 d | ƒ |  j | j d d d | ƒ d S(   s   Require valid mapss   a 0x10s7   Dump ...
0x08083540 <main+0>:    lea    0x4(%esp),%ecx
t   asdlkfjaadfs¨   005a3000-005a4000 rw-p 00035000 08:06 65575      /lib/libncurses.so.5.7
00b67000-00b68000 r-xp 00000000 00:00 0          [vdso]
00c67000-00c68000 r--p 00000000 00:00 0 i    R   i 0Z R   i @Z R    s   rw-pR!   s   /lib/libncurses.so.5.7i   i p¶ i €¶ s   r-xps   [vdso]i   i pÆ i €Æ s   r--pN(   Rž   R%   R    R    R   R	   (   R   R   R¡   R   R—   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_invalid_02_mapsˆ  s$    c         C   sY   d } d } d } t  j d d ƒ t _ t | | | d t ƒ} |  j | d k	 | ƒ d S(   s   Debug mode workss   a 0x10s7   Dump ...
0x08083540 <main+0>:    lea    0x4(%esp),%ecx
s¨   005a3000-005a4000 rw-p 00035000 08:06 65575      /lib/libncurses.so.5.7
00b67000-00b68000 r-xp 00000000 00:00 0          [vdso]
00c67000-00c68000 r--p 00000000 00:00 0 t   prefixs   parse_segv-stderr-R   N(   t   tempfilet   NamedTemporaryFilet   syst   stderrR    RY   RŸ   R	   (   R   R   R¡   R   R—   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt
   test_debug£  s    c         C   s¼   d } t  t | d ƒ } | j d ƒ } |  j | d t | ƒ ƒ | j d ƒ } |  j | d t | ƒ ƒ | j d ƒ } |  j | d t | ƒ ƒ | j d	 ƒ } |  j | d
 t | ƒ ƒ d S(   s   Sub-register parsings&   0x08083540 <main+0>:    mov    $1,%ecxR5   s   %rdxl   €À~ÿÿ s   %edxl   €À~ s   %dxi€  s   %dli€   N(   R    t   regs64Rd   t   assertEqualt   hex(   R   R¡   R—   Rh   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_register_values°  s    c         C   sÕ  d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j | j d ƒ d | j d ƒ |  j | j d ƒ d | j d ƒ |  j | j d ƒ d | j d ƒ |  j | j d	 ƒ d
 | j d ƒ |  j | j d ƒ d d ƒ |  j | j d ƒ d | j d ƒ |  j | j d ƒ d | j d ƒ |  j | j d ƒ d | j d ƒ |  j | j d ƒ d | j d ƒ d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j | j d ƒ d | j d ƒ d S(   s   Handles unknown segfaultss&   0x08083540 <main+0>:    mov    $1,%ecxs   (%ecx)l   @/ t   ecxs
   0x10(%ecx)l   P/ s   -0x20(%ecx)l    / s
   %fs:(%ecx)l   D/ t	   0x3404403iD@s   *0x40(%edi)iÀ4t   edis   (%edx,%ebx,1)iõï& t   ebxs   (%eax,%ebx,1)ióï& s   0x10(,%ebx,1)ið& s&   0x08083540 <main+0>:    mov    $1,%rcxs   (%rax,%rbx,1)t   rbxN(   R    R   R   Rƒ   t   assertFalseR´   Rw   R³   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_unknown¿  s$    ########c         C   sÖ   d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s   Handles PC in missing VMAs-   0x00083540 <main+0>:    lea    0x4(%esp),%ecxs1   PC (0x00083540) not located in a known VMA regions   executing unknown VMAs   0x00083544:s1   PC (0x00083544) not located in a known VMA regionN(   R    R   R   Rƒ   RŸ   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_pc_missingÚ  s    c         C   sm   d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s   Handles PC in NULL VMAs-   0x00000540 <main+0>:    lea    0x4(%esp),%ecxs1   PC (0x00000540) not located in a known VMA regions   executing NULL VMAN(   R    R   R   Rƒ   RŸ   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_pc_nullë  s    c         C   sm   d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s   Handles PC in writable NX VMAs-   0x005a3000 <main+0>:    lea    0x4(%esp),%ecxs-   PC (0x005a3000) in non-executable VMA region:s-   executing writable VMA /lib/libncurses.so.5.7N(   R    R   R   Rƒ   RŸ   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_pc_nx_writableõ  s    c         C   sm   d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s!   Handles PC in non-writable NX VMAs-   0x00dfb000 <main+0>:    lea    0x4(%esp),%ecxs-   PC (0x00dfb000) in non-executable VMA region:s2   executing non-writable VMA /lib/libreadline.so.5.2N(   R    R   R   Rƒ   RŸ   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_pc_nx_unwritableÿ  s    c         C   sà   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s   Handles source in missing VMAs&   ecx            0x0006af24   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)sB   source "-0x4(%ecx)" (0x0006af20) not located in a known VMA regions   reading unknown VMAs$   0x08083547 <main+7>:    callq  *%ecxs=   source "*%ecx" (0x0006af24) not located in a known VMA regionN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_src_missing	  s    
c         C   sw   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s   Handles source in NULL VMAs&   ecx            0x00000024   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)sB   source "-0x4(%ecx)" (0x00000020) not located in a known VMA regions   reading NULL VMAN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_src_null  s    
c         C   s£   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s"   Handles source not in readable VMAs&   ecx            0x0026c080   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)s<   source "-0x4(%ecx)" (0x0026c07c) in non-readable VMA region:s*   reading VMA /lib/tls/i686/cmov/libc-2.9.sos   Stack memory exhausteds&   Stack pointer not within stack segmentN(   R   R    R   Rƒ   RŸ   R¼   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_src_not_readable*  s    
c         C   sw   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s#   Handles destintation in missing VMAs&   esp            0x0006af24   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)sC   destination "(%esp)" (0x0006af24) not located in a known VMA regions   writing unknown VMAN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_dest_missing7  s    
c         C   sw   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s    Handles destintation in NULL VMAs&   esp            0x00000024   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)sC   destination "(%esp)" (0x00000024) not located in a known VMA regions   writing NULL VMAN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_dest_nullC  s    
c         C   sw   t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d S(   s'   Handles destination not in writable VMAs&   esp            0x08048080   0xbfc6af24s)   0x08083547 <main+7>:    pushl  -0x4(%ecx)s=   destination "(%esp)" (0x08048080) in non-writable VMA region:s   writing VMA /usr/bin/gdbN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_dest_not_writableO  s    
c         C   sZ   d } t  t | t ƒ } |  j t | j ƒ d } t  t | t ƒ } |  j t | j ƒ d S(   s   Rejects insane disassembliess)   0x08083547 <main+7>:    pushl  -0x4(blah)s(   0x08083547 <main+7>:    pushl  -04(%ecx)N(   R    R   R   Rž   R%   Rƒ   (   R   R¡   R—   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_crackful_disasmZ  s    c         C   sG  t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ t  d } d } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ t  d } d	 } t | | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d
 | k | ƒ |  j d | k | ƒ d S(   s   Handles walking off the stacks&   esp            0xbfc56ff0   0xbfc56ff0s"   0x08083547 <main+7>:    push  %eaxs]   destination "(%esp)" (0xbfc56ff0) not located in a known VMA region (needed writable region)!s&   esp            0xbfc56fff   0xbfc56fffs)   0x08083547 <main+7>:    callq  0x08083540s]   destination "(%esp)" (0xbfc56fff) not located in a known VMA region (needed writable region)!s   Stack memory exhausteds&   esp            0xdfc56000   0xdfc56000s&   0x08083540 <main+0>:    mov    $1,%rcxsK   SP (0xdfc56000) not located in a known VMA region (needed readable region)!s&   Stack pointer not within stack segmentN(   R   R    R   Rƒ   RŸ   (   R   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   test_segv_stack_failuree  s(    


c         C   sÀ   d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ |  j d | k | ƒ d } t  t | t ƒ } | j ƒ  \ } } } |  j | | ƒ |  j d | k | ƒ d S(   s#   Handles unknown segfaults in kernels   0x0056e010: rets-   Reason could not be automatically determined.s%   (Unhandled exception in kernel code?)s%   0x00b67422 <__kernel_vsyscall+2>: retsS   Reason could not be automatically determined. (Unhandled exception in kernel code?)N(   R    R   R   Rƒ   R¼   RŸ   (   R   R¡   R—   R   R€   R   (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyRÉ   ‚  s    (   R„   R…   t   __doc__R›   Rœ   R¢   R©   Rª   R¬   R²   R¶   R½   R¾   R¿   RÀ   RÁ   RÂ   RÃ   RÄ   RÅ   RÆ   RÇ   RÈ   RÉ   (    (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyRš   é  s.   				o							
	
	
								(   R°   RD   R   t   objectR    R˜   R„   R&   t   argvt   exitt   filet   readR—   Rƒ   R   R€   R   t   rct   unittestR®   R   R³   R   R¡   t   TestCaseRš   t   main(    (    (    s-   /usr/share/apport/general-hooks/parse_segv.pyt   <module>   s6   $ÿ ;	.	$"&ÿ ­