o vf@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlmZe jdkrndZddlmZddlmZddlmZeefnd ZddlmZddlmZe Zddl!Z!ddl"Z"ddl#Z"dd l$m%Z&dd l'm(Z(ej)*d d Z+de+Z,de+Z-dZ.dZ/dZ0dZ1gdZ2ddZ3d+ddZ4d+ddZ5ddZ6d+ddZ7dd Z8d!d"Z9d#d$Z:d%d&Z;d'd(ZdS),z;Representation of and data collection for a problem report.N) ExpatError3F)URLError)urlopen)unquoteT)impl)kill_pkttyagentAPPORT_DATA_DIRz/usr/share/apportz%s/package-hooks/z%s/general-hooks/z/optz~/.apport-ignore.xmlz/etc/apport/blacklist.dz/etc/apport/whitelist.d) shbashdashcshtcshzpython*zruby*phpzperl*zmono*awkcCsTzt|Wn tyYdSwt|D]}||vr'||t||qdS)z7Recursively add dependencies of package to depends_set.N) packaging get_version ValueErrorget_dependenciesadd_transitive_dependencies)package depends_setdr//usr/lib/python3/dist-packages/apport/report.pyr9s   rcCs,ts |dur tj||dStd||fS)zrUse readlink() to resolve link. Return a string representing the path to which the symbolic link points. Ndir_fd /proc/%s/%s)_python2osreadlink)pathpidrrrr_read_proc_linkFs r$c Csz>ts|durtj|tjtjB|d}nd||f}t|d}|jdddWdWS1s7wYWdSt t fyX}z dt |WYd}~Sd}~ww) zXRead file content. Return its content, or return a textual error if it failed. NrrrbUTF-8replaceerrorsError: ) rr openO_RDONLY O_CLOEXECioreadstripdecodeOSErrorIOErrorstr)r"r#r proc_filefderrr_read_proc_fileQs  (r8c sd}trdSz%tdfddd}|}WdW|S1s$wYW|SttfyE}z dt|WYd}~Sd}~ww) zRead /proc/pid/maps. Since /proc/$pid/maps may become unreadable unless we are ptracing the process, detect this, and attempt to attach/detach. z%Error: unable to read /proc maps filezDError: python2 does not provide a secure way to read /proc maps filemapscstj||dS)Nr)r r+)r"mode proc_pid_fdrrnsz_read_maps..)openerNr*)rr+r/r0r2r3r4)r<r9r6r7rr;r _read_mapsbs r?cCstj|tjtj|d}z |j|ddd}Wntjy4||\}}tdt||j |fw|j dkr<|S|rF|j ddd}nd }td t||j |f) zRun command and capture its output. Try to execute given command (argv list) and return its stdout, or return a textual error if it failed. )stdoutstderrenvi)inputtimeoutrz0Error: command %s timedout with exit code %i: %sr&r'r(z.Error: command %s failed with exit code %i: %s) subprocessPopenPIPESTDOUT communicateTimeoutExpiredkillr2r4 returncoder1)commandrCrBspouterrsrrr_command_outputus(     rRc CsTtr |jds dSnd|jvrdS|jD]}|jtjjjkr|j dkrz|jdj }Wn t y5Yqw||vr=dS| | r|jdjtjjjkr|jdj }tr]|d}||}t|tjrs|}tsr|d}n t|trts|d}zt|}Wn tyYqw||sdSqtr|jdj dS|jdj S)zxCheck if given report matches the given bug pattern XML DOM node. Return the bug URL on match, otherwise None. urlNrekeyrr&)r attributeshas_key childNodesnodeTypexmldomNode ELEMENT_NODEnodeName nodeValueKeyError normalize hasChildNodes TEXT_NODEencode isinstanceproblem_reportCompressedValue get_valuebytesrTcompile Exceptionsearch)reportpatterncrUregexpvre_crrr_check_bug_patternsP             rsc Csdztr|d}tjj|}Wn ttfyYdSw|dD] }t ||}|r/|Sq"dS)Nr&rn) rrdrZr[minidom parseStringrUnicodeEncodeErrorgetElementsByTagNamers)rmpatternsr[rnrSrrr_check_bug_patternss  rycCsJ|jD]}|jtjjjkr|jdkr|| |qt |qdS)z6Recursively remove whitespace from given XML DOM node.rEN) rXrYrZr[r\rcr_r0unlink removeChild_dom_remove_space)noderorrrr|s   r|c Cstj|sdSi}zNt|}tt||d|Wdn1s%wYz |d||WWdStyX}zt| drK|d|nWYd}~WdSd}~wwt ybYdSt ytj tj |ddd}t|d |<td |tYdSw) NFexecadd_infoz add_info()Tr-_ HookError_zhook %s crashed:)r r"existsr+r~rjr/ TypeErrorr4 startswith StopIterationrksplitextbasenamer' traceback format_excapporterror print_exc)rmuihooksymbr6r7hooknamerrr _run_hooks6         rcCs|r$tj}|ddtj}|tj|dd<tj||d<nd}ztjd|g|d WStj y?YdSw)z-Return path of command, preferring extra_pathPATHrErNwhichrB) r environcopygetsplitpathsepjoinrF check_outputr1r0CalledProcessError)rN extra_pathrBpartsrrr_which_extrapaths rc@s>eZdZdZdFddZddZdd ZdGd d Zd d ZddZ ddZ ddZ ddZ e ddZddgfddZdgdfddZdGddZdHddZd d!ZdHd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Zd2d3Zd4d5Zd6d7Zd8d9Zd:d;Z dd?Z"d@dAZ#dBdCZ$e%dHdDdEZ&dS)IReportzA problem report specific to apport (crash or bug). This class wraps a standard ProblemReport and adds methods for collecting standard debugging data.CrashNcCs tj|||d|_d|_dS)a,Initialize a fresh problem report. date is the desired date/time string; if None (default), the current local time is used. If the report is attached to a process ID, this should be set in self.pid, so that e. g. hooks can use it to collect additional data. N)rf ProblemReport__init__r#_proc_maps_cache)selftypedaterrrrs  zReport.__init__cCsxd}t|}|r|dd|7}zt|s/t|}|r(|d|7}W|S|d7}W|SW|Sty;Y|Sw)zReturn a string suitable for appending to Package/Dependencies. If package has only unmodified files, return the empty string. If not, return ' [modified: ...]' with a list of modified files. rEz [modified: %s] z [origin: %s]z [origin: unknown])rget_modified_filesris_distro_packageget_package_originr)rrsuffixmodoriginrrr_customized_package_suffixs$     z!Report._customized_package_suffixcCsFzt|}Wn tyd}Ynwd||pd||f|d<|S)aAdd Package: field Determine the version of the given package (uses "(not installed") for uninstalled packages) and add Package: field to report. This also checks for any modified files. Return determined package version (None for uninstalled). N%s %s%sz(not installed)Package)rrrr)rrversionrrr add_package6s    zReport.add_packagec Cs|sd|vr|ddkr|d}ntj|d}|sdS||}|s(d|vr;z t||d<Wn ty:Ynw|s?dSt||d<tg}t ||d|d <t |D]/}zt |}Wn tyiYqWw|d rv|d d 7<|d d ||| |f7<qWdS) aAdd packaging information. If package is not given, the report must have ExecutablePath. This adds: - Package: package name and installed version - SourcePackage: source package name (if possible to determine) - PackageArchitecture: processor architecture this package was built for - Dependencies: package names and versions of all dependencies and pre-dependencies; this also checks if the files are unmodified and appends a list of all modified files ExecutablePath ProblemType KernelCrashrN SourcePackagePackageArchitecturerE Dependencies r) r fileutilsfind_file_packagerr get_sourcerget_architecturesetrsortedrr)rrr dependenciesdeprqrrradd_package_infoIs>           zReport.add_package_infoc Csd|d|d|ddf|d<|d}tddd |g|d <tdd |g|d <tdd d |g|d|<ddl}td| }||}Wdn1sQwYd|vrj|d}tdd d |g|d|<g}d|vr|dD]}|d|d} | r| |vr|| qt|D]} tdd d | g|d| <q|drd} t| t|dd} | r| dr| d|d<| dr| d|d<dSdSdSdSdS)zAdd info about an installed Snap This adds a Snap: field, containing name, version and channel. It adds a SnapSource: field, if the snap has a Launchpad contact defined. z %s %s (%s)namerchannelunknownSnapsnapchangesz --abs-timez Snap.Changes connectionszSnap.Connectionsinfoz Snap.Info.%srNz/snap/%s/current/meta/snap.yamlbaseplugszdefault-providercontactzX^https?:\/\/.*launchpad\.net\/((?:[^\/]+\/\+source\/)?[^\/]+)(?:.*field\.tags?=([^&]+))?rE SnapSourceSnapTags) rrRyamlr+ safe_loadappendrTrlrgroup) rrsnapnamerf snap_metar providersplugdpproviderpmrrr add_snap_info~sL           zReport.add_snap_infocCsdd|vr dtj|d<d|vr$t}d|d|d|df|d<d|vr0t|d<d Sd S) aAdd operating system information. This adds: - DistroRelease: NAME and VERSION from /etc/os-release, or 'lsb_release -sir' output - Architecture: system architecture in distro specific notation - Uname: uname -srm output DistroReleasez%s %sUnamez%s %s %srr ArchitectureN)rrget_os_versionr unameget_system_architecture)rurrr add_os_infos zReport.add_os_infocsRttdfddtD}||r#d||d<dSd|d<dS)zoAdd information about the user. This adds: - UserGroups: system groups the user is in rcs(g|]\}}}}|vr|dkr|qS)ir).0rrgidmembuserrr sz(Report.add_user_info..r UserGroupszN/AN)pwdgetpwuidr geteuidgrpgetgrallsortr)rgroupsrrr add_user_infos  zReport.add_user_infoc sxd|vrdStj|dttfddtsdSd}|dD]}z |dd\}}Wn ty8Yq#w|dkrA|}nq#|sFdS|d d }gd }t |d kr|d d r| dr|ddkrt |dkr| |d }|r|d|d<||d<dSd|d |d<dS|d=t |d kr|d d s^t |d kr|d drd|vrtj |d|d|d<t |dtjr|d|d<tj|d|d<d|vr|kr|D]-}t ||dtjr||d} tjtj| |kr |d|d<| |d<nqd|vr8tj|ddkr:|d|d<|} | r2| |d<dSd|d<dSdSdS)zCheck if process is a script. Use ExecutablePath, ProcStatus and ProcCmdline to determine if process is an interpreted script. If so, set InterpreterPath accordingly. rNcs t|SN)fnmatch)i exebasenamerrr=s z+Report._check_interpreted.. ProcStatus rzName: ProcCmdline)z /usr/bin/z /usr/sbin/z/bin/z/sbin/rrpythonz-mInterpreterPathz)Cannot determine path of python module %sUnreportableReason.ProcCwdrtwistdz&Cannot determine twistd client program)r r"ranyfilter interpreters splitlinesrrlenr_python_module_pathraccessR_OKrealpath_twistd_executable) rrlinekrqcmdargsbindirsr"rargvexeexerrr_check_interpretedsj "        zReport._check_interpretedcCs|dddd}|ro|ddd}|dds*|dd s*|dd r8t|dkr4|dS|dSt|ddkrh|ddd krh|ddd krh|ddd}d |vsdd |vsdd|vrh|dS|d|s dS)z5Determine the twistd client program from ProcCmdline.rrrNr=rz--filez--pythonz--sourcerrys)rrrpop)rargsargoptsrrrrs* 0 zReport._twistd_executablecCs8ztj|}Wn tyYdSw|durdS|jS)z%Determine path of given Python moduleN) importlibutil find_spec ImportErrorr)modulespecrrrr/s zReport._python_module_pathc Cs|sO|s |jp t}|jst||_t|}tsOztd|tjtjBtj B}Wn$t yN}z|j t j t j fvr?td|j t jkrItdd}~wwz td|||d<Wn t ybYnw|j|||dtd|||d <td ||d |d <t||d <d|vrz td|||d<Wn$t y}z|j t j t j fvrtd|j t jkrtdd}~wwdD]}|dd|r|dtd|d|d<nqtj|dstd|d|ttt|dj|d<|d ddddd d|d <ztdkr td||}|dkr ||d<Wn tt fy-Ynw|||}|r?|d|d<dSdS)aAdd /proc/pid information. If neither pid nor self.pid are given, it defaults to the process' current pid and sets self.pid. This adds the following fields: - ExecutablePath: /proc/pid/exe contents; if the crashed process is interpreted, this contains the script path instead - InterpreterPath: /proc/pid/exe contents if the crashed process is interpreted; otherwise this key does not exist - ExecutableTimestamp: time stamp of ExecutablePath, for comparing at report time - ProcEnviron: A subset of the process' environment (only some standard variables that do not disclose potentially sensitive information, plus the ones mentioned in extraenv) - ProcCmdline: /proc/pid/cmdline contents - ProcStatus: /proc/pid/status contents - ProcMaps: /proc/pid/maps contents - ProcAttrCurrent: /proc/pid/attr/current contents, if not "unconfined" - CurrentDesktop: Value of $XDG_CURRENT_DESKTOP, if present - _LogindSession: logind cgroup path, if present (Used for filtering out crashes that happened in a session that is not running any more) /proc/%sznot accessiblezinvalid processNcwdr)r#r<extraenvstatusrcmdlinerrProcMapsrr)rofsrwfs squashmnt persistmntz/%s/z/%sz%s does not existExecutableTimestamp\z\\rz\ rz attr/current unconfinedProcAttrCurrent_LogindSession) r#r getpidintr4rr+r,O_PATH O_DIRECTORYr2errnoEPERMEACCESrENOENTr$add_proc_environr8rstripr?rrr"rrstatst_mtimer'getuidr3get_logind_session)rr#r<r*r7rvalretrrr add_proc_info:sx "    $   zReport.add_proc_infocCs gd|}|s#|st}t|}ts#td|tjtjBtjB}d|d<td|| dd}| dr<||d<dS| d D]}| d d d |vrb|drY|dd7<|d|7<qA| d r| d d d }d|vswd|vr|dr|dd7<|dd7<qA|dkr|dr|dd7<|dd7<qA| dr|dr|dd7<|dd7<qA| dr|dr|dd7<|dd7<qA| dr|dr|dd7<|dd7<qA| dr| d d d |d<qAdS)aAdd environment information. If pid is not given, it defaults to the process' current pid. This adds the following fields: - ProcEnviron: A subset of the process' environment (only some standard variables that do not disclose potentially sensitive information, plus the ones mentioned in extraenv) - CurrentDesktop: Value of $XDG_CURRENT_DESKTOP, if present )SHELLTERMLANGUAGELANGLC_CTYPE LC_COLLATELC_TIME LC_NUMERIC LC_MONETARY LC_MESSAGESLC_PAPERLC_NAME LC_ADDRESS LC_TELEPHONELC_MEASUREMENTLC_IDENTIFICATIONLOCPATHr(rE ProcEnvironrr\nzError:rrrrzPATH=z/homez/tmpzPATH=(custom, user)zG/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/gameszPATH=(custom, no user)zXDG_RUNTIME_DIR=zXDG_RUNTIME_DIR=z LD_PRELOAD=zLD_PRELOAD=zLD_LIBRARY_PATH=zLD_LIBRARY_PATH=zXDG_CURRENT_DESKTOP=CurrentDesktopN) r r7r4rr+r,r9r:r8r'rr)rr#r*r< safe_varsrBrrrrrr?sZ        zReport.add_proc_environc Cs*d|vrdSd}d}zt|ddr't\}}t||dt|d}|dd}dd ||g}ztj|tj tj tj d }Wnt yXYW|rVt |dSdSw|j d |j d |j d |j d|j} |dk}|r| |d<W|rt ||S|rt |ww)zWAdd information from kernel crash. This needs a VmCore in the Report. VmCoreNFfindTrrcrashz/usr/lib/debug/boot/vmlinux-%s)stdinr@rAz bt -a -f zps zrunq zquit r Stacktrace)hasattrtempfilemkstempr writecloserrFrGrHrIr2rzr`r@r/wait) rdebugdir unlink_corerFr6corekverrNrrPrrradd_kernel_crash_infosT            zReport.add_kernel_crash_infocCsd|vsd|vr dSdddddd d d }|||\}}|s)ttjttjd |gd 7}g}|D]\}}|||ddd|g7}q5|d|ddg7}t||dj ddd} d| vsed| vrd| vrvd dd| D} nd| vrd dd| D} n| d} d| } | |d<t | | ddd rttjttjd!td"tj} | | } | d| D]}|d#d$ ||d<qd%|vrd&|d%vr|d%|d'<|d%=d(|vr|d(d)r|d(|d'<|d(=d'|vr'td*|d'}|r$|d+|d'<|d'd,r#|d'dd-|d'<n|d'=d.|vr=||}|r?||d/<dSdSdS)0a<Add information from gdb. This requires that the report has a CoreDump and an ExecutablePath. This adds the following fields: - Registers: Output of gdb's 'info registers' command - Disassembly: Output of gdb's 'x/16i $pc' command - Stacktrace: Output of gdb's 'bt full' command - ThreadStacktrace: Output of gdb's 'thread apply all bt full' command - StacktraceTop: simplified stacktrace (topmost 5 functions) for inline inclusion into bug reports and easier processing - AssertionMessage: Value of __abort_msg, __glib_assert_msg, or __nih_abort_msg if present The optional rootdir can specify a root directory which has the executable, libraries, and debug symbols. This does not require chroot() or root privileges, it just instructs gdb to search for the files there. Raises a IOError if the core dump is invalid/truncated, or OSError if calling gdb fails, or FileNotFoundError if gdb or the crashing executable cannot be found. CoreDumprNzinfo registersz x/16i $pczbt fullzthread apply all bt fullzprint __abort_msg->msgzprint __glib_assert_msgzprint (char*) __nih_abort_msg) Registers DisassemblyraThreadStacktraceAssertionMessageGLibAssertionMessageNihAssertionMessagezgdb not found in retracing env)z--batch--exzset backtrace limit 2000rtzp -99 separatorrr&r'r(z%is truncated: expected core file sizezis not a core dumpwarning:rcSg|]}d|vr|qS)rvrrrrrrr0z'Report.add_gdb_info..Warning:cSrw)rzrrxrrrr3ryrzInvalid core dump: rzNo such file or directory.z&executable file for coredump not foundz^\$\d+\s*=\s*-99$z z . rrz"ERROR:rqrs$z(^\$\d+\s+=\s+0x[0-9a-fA-F]+\s+"(.*)"\s*$rrZraStacktraceAddressSignature) gdb_commandFileNotFoundErrorr;r>r strerroritemsrrRr1rr r0r3rendswithrTrj MULTILINErr'rmatchr_gen_stacktrace_topcrash_signature_addresses)rrootdir gdb_sandbox gdb_reportsgdb_cmdr value_keysrcmdrPwarningsreasonpart_rerpartraddr_signaturerrr add_gdb_infos              zReport.add_gdb_infocCsdtgd}dgd}d}d}d}d}td}td}td} |d D]~} || } | s9|| } | s9q(|r=|r| d rQ| d dd d} nd } |ra| d s^| dvr_q(d}| dsj| |vrd}d}dgd}| drzd}| dkrd}q(d}| d p| d} | d}|t|kr| |s| ||<|d7}q(d | |d<d S)zBuild field StacktraceTop as the top five functions of Stacktrace. Signal handler invocations and related functions are skipped since they are generally not useful for triaging and duplicate detection. )g_logvg_log IA__g_log IA__g_logvg_assert_warningIA__g_assert_warning __GI_abort_XErrorrErFzD^#(\d+)\s+(?:0x(?:\w+)\s+in\s+\*?(.*)|()\s*)$z0^#(\d+)\s+(?:(.*)|()\s*)$z,^(__.*_s?sse\d+(?:_\w+)?|__kernel_vsyscall)$rar(N_X)handle_response handle_error XWindowEventrTrrr StacktraceTop) rrTrjr rrrrrrr0)runwind_functionstoptracedepthunwound unwindingunwinding_xerrorbt_fn_rebt_fn_noaddr_reignore_functions_rerrfnframefunctionrrrresP           zReport._gen_stacktrace_topcCs||||}t|S)aRun hook script for collecting package specific data. A hook script needs to be in _hook_dir/.py or in _common_hook_dir/*.py and has to contain a function 'add_info(report, ui)' that takes and modifies a Report, and gets an UserInterface reference for interactivity. return True if the hook requested to stop the report filing process, False otherwise. )_add_hooks_infor)rrr srcpackagerFrrradd_hooks_infos zReport.add_hooks_infoc Cs|s|d}|r|d}d|vrd||d<dS|s"|d}|r6|d}d|vr6d||d<dStg}d}tj|dd }|trM|}n&|rsztj |D]}|trgtj |rg|}nqVWn t yrYnw|rt |t tkr|tj|d d d tj|}t |t tks}ttd D] }t|||rdSq|r|D]} t||tj| |drdSq|r|D]} t||tj| d|rdSqdS)Nrr/zinvalid Package: %srrzinvalid SourcePackage: %srrEsharerz package-hooksz/*.pyTz.pyz source_%s.pyF)rr _hook_dirr r"rr_opt_dirrr get_filesisfilerrrrdirnameglob_common_hook_dirr) rrrr hook_dirsopt_path exec_pathrrhook_dirrrrrsb          zReport._add_hooks_infoc Csj|sdSzt|}|jddd}|Wn ttfy#YdSwd|vr*dSt||}|r3|SdS)aCheck bug patterns loaded from the specified url. Return bug URL on match, or None otherwise. The url must refer to a valid XML document with the following syntax: root element := patterns := * pattern := regular expression* + For example: ba.*r ^\S* 1-2$ write_(hello|goodbye) Nr&r'r(z404 Not Found)r���r/���r1���rf��r3���r���ry���)r���rS���r���rx���r���r���r���search_bug_patterns��s���  zReport.search_bug_patternsc����������� ��� ���C���sN��t�t�d�}td|}d}d}d}zBz"t|tjtjB�}t |}t |j r7t |d}|d}W�n �ttfyC���Y�nw�W�|durN|��n|durWt|�n|dura|��w�|durkt|�w�w�|dkr{tj�ddd}n z tjj|}W�n�ty�}�z tdtt|f�d}~ww�|j��t|j�|S�) zRead ignore list XML file and return a DOM tree. Return an empty DOM tree if file does not exist. Raises ValueError if the file exists but is invalid XML. r��~rE���NriP��r���z%s has invalid format: %s)r���r���r ���r��� _ignore_filer'���r+��� O_NOFOLLOWr,���fstatrA��S_ISREGst_modefdopenr/���r3���r2���rf��rZ���r[���getDOMImplementationcreateDocumentrt���ru���r���r���r4���documentElementra���r|���) r���homedirifpathcontentsr6���r���str[���r7���r���r���r���_get_ignore_dom��sJ���           zReport._get_ignore_domc�������������� ���C���s��d|�v�sJ�zGt�tD�]?}z4tt�jt|!}|D�]}|�|�d�kr1�W�d���W��W�dS�qW�d���n1�s<w���Y��W�q �tyK���Y�q w�W�n �tyV���Y�nw�zHt �}t�t D�]2}z'tt�jt |}|D�] }| |��qoW�d���n1�sw���Y��W�q`�ty���Y�q`w�|r|�d�|vrW�dS�W�n �ty���Y�nw�z|� �}W�n�t tfy���td�t��Y�dS�w�z tt�|�d�j}W�n �ty���Y�dS�w�z!|dD�]}|d|�d�krt|d|kr�W�dS�qW�dS��t tfy ���Y�dS�w�) a\��Check if current report should not be presented. Reports can be suppressed by per-user blacklisting in ~/.apport-ignore.xml (in the real UID's home) and /etc/apport/blacklist.d/. For environments where you are only interested in crashes of some programs, you can also create a whitelist in /etc/apport/whitelist.d/, everything which does not match gets ignored then. This requires the ExecutablePath attribute. Throws a ValueError if the file has an invalid format. Privileges may need to be dropped before calling this. r���NTzCould not get ignore file:Fignoreprogrammtime)r ���listdir_blacklist_dirr+���r"���r���r0���r3���r2���r���_whitelist_dirr���r��r���r`���r���r���r���r���r8��rA��rB��rw��� getAttributefloat)r���r���r6���r�� whitelistr[��� cur_mtimer��r���r���r��� check_ignoredE��s~���        zReport.check_ignoredc�������������� ���C���s.��d|�v�sJ�|���}zttt|�d�j}W�n�ty2�}�z|jtjkr-W�Y�d}~dS��d}~ww�| dD�]}| d|�d�krK| d|��nq8| d}| d|�d��| d|�|j |�tt�d�}td|}t|d}|j|d d d �W�d���n1�sw���Y��|��dS�) a~��Ignore future crashes of this executable. Add a ignore list entry for this report to ~/.apport-ignore.xml, so that future reports for this ExecutablePath are not presented to the user any more. Throws a ValueError if the file already exists and has an invalid format. Privileges may need to be dropped before calling this. r���Nr��r��r��r��r��wz r���) addindentnewl)r��r4���r8��r ���rA��rB��r2���r;��r>��rw���r�� setAttribute createElementr�� appendChildr���r���r���r��r'���r+���writexmlrz���)r���r[���r��r7���r��r��ignore_file_pathr6���r���r���r��� mark_ignore��s2���         zReport.mark_ignorec�����������������C���sT���|��dsdS�dd�|�d��D�}t|dk�r|ddkS�|dt|d�kS�) a��Check whether StackTrace can be considered 'useful'. The current heuristic is to consider it useless if it either is shorter than three lines and has any unknown function, or for longer traces, a minority of known functions. r��Fc�����������������S���s���g�|�]}|�d�qS�)??)r���)r���r���r���r���r���r�����s����z0Report.has_useful_stacktrace.<locals>.<listcomp>r��Tr���g�������@)r���r ��r��count)r��� unknown_fnr���r���r���has_useful_stacktrace��s ���  zReport.has_useful_stacktracec�����������������C���s<���|��dd�D�]}|dd��}|dkr|��S�qdS�)z(Return topmost function in StacktraceTopr��rE���r��r���r��N)r���r ��r���r0���)r���r��fnamer���r���r���stacktrace_top_function��s ���zReport.stacktrace_top_functionc�������������� ���C���s\��|��ddkrd|�v�rd|�v�rdtj|�d�|�d�f�S�d|�v�rvd|�v�rvd|�v�rvddd d d d }|��}|r<d |�}nd}d}d|�v�r\d|�v�r\|�d�|�d�kr\|�d�dkr\d|�d��}dtj|�d�|�|��dd|��d�||f�S�d|�v�rd|�v�r|�d��}t|dk�rdS�t|dk�rdtj|�d�|d�f�S�td}t|d�}d}|dkr| ||�}|r| d} | d}n|d8�}|dkstj|�d�} |d�} | dd�} t d t | �| }|r| d} nd} |d!kr | |�d�krd"}n| }nd#|�}d$| | |f�}| r|d%| �7�}|S�|��d&d'krFd'|�v�rFd(|�d'��}|��d)rD|d*|�d)��d��7�}|S�|��d&d+krqd,|�v�rq|�d,�}| d-rg| d.dd�}|S�| d.dd�}|S�|��d&d+krd/|�v�rd}d0|�v�r|d1|�d0��d2�7�}||�d/�d3�7�}d4|�v�r|d5|�d4��d6�7�}|d.7�}|S�dS�)7aZ��Create an appropriate title for a crash database entry. This contains the topmost function name from the stack trace and the signal (for signal crashes) or the Python exception (for unhandled Python exceptions). Return None if the report is not a crash or a default title could not be generated. Signal6r���rq��z%s assert failure: %sr��SIGILLSIGABRTSIGFPESIGSEGVSIGPIPE)4r��81113z in %s()rE���r���r���allz [non-native %s package]z%s crashed with %s%s%szsignal Tracebackr���Nr��z%s crashed with %sr���z^\s*File\s*"(\S+)".* in (.+)$r���r���:z ^%s: (.+)$<module>__main__z%s()z%s crashed with %s in %sz: %sr���r���z$package %s failed to install/upgrade ErrorMessagez: KernelOopsOopsTextz$------------[ cut here ]------------r���Failure MachineType[z] z failureNonfreeKernelModulesz [non-free: ])r���r ���r"���r���r��r ��r��rT���rj���r��r���r���escaper���)r��� signal_namesr�� arch_mismatchtracetrace_rer���r��r��� module_pathr"��� last_line exceptionmessagecontexttitleoopsr���r���r���standard_title��s���  ,               zReport.standard_titlec�����������������C���s���g�}|��ddd�|��dd��D�]-}|sq|�dd�\}}t|}|dur?|dkr?|dur?t||dk�r?||�q|S�) z=Return list of obsolete packages in Package and Dependencies.r���rE���r���r���Nr���Noner���)r���r ��r���r���get_available_versioncompare_versionsr���)r���obsoleter��pkgveravailr���r���r���obsolete_packagesW��s���$ ( zReport.obsolete_packagesc�����������������C���s��d|�vr |�d�dvr dS�d|�v�r8|�d�dkr8d}t�d}|�d��D�]}||}|r5|d |d �7�}q#|S�|�d d krTd |�v�rT|�d�d �|�d ��}t�dd|S�d|�v�rd |�v�rd|�d�|�d �f�}t�d}|�d��}t|dk�rydS�|D�]}||}|r|d |d p|d�7�}q{�dS�|S�d|�v�r1|�d��}d}t|d krt�d|d�}|r|�d�d �|d �S�dS�t|dk�rdS�t�d}|D�]7}||}|r|ddkr|d |d�7�}q|d } tj | rtj | } |d| |df�7�}q|d� d d�} z | d|�d��7�} W�n �t y&���Y�nw�|�d�d �| �|�S�|�d�dkrmd |�v�rmd!|�d �v�sKd"|�d �v�rm|�d �}|�d#r]|d$|�d#��7�}|�d%rk|d$|�d%��7�}|S�d&|�v�rd'} g�} |�d&� d(D�]d}|d)rt�d*|} | r| d }|sJ�d+|�| |�|d,r|�|}|r| |�q}|d-rd.} q}| rd}|r|d�d/kr|�|}|r| |�q}d'} q}| rd | S�dS�)0a��Get a signature string for a crash. This is suitable for identifying duplicates. For signal crashes this the concatenation of ExecutablePath, Signal number, and StacktraceTop function names, separated by a colon. If StacktraceTop has unknown functions or the report lacks any of those fields, return None. In this case, you can use crash_signature_addresses() to get a less precise duplicate signature based on addresses instead of symbol names. For assertion failures, it is the concatenation of ExecutablePath and assertion message, separated by colons. For Python crashes, this concatenates the ExecutablePath, exception name, and Traceback function names, again separated by a colon. For suspend/resume failures, this concatenates whether it was a suspend or resume failure with the hardware identifier and the BIOS version, if it exists. r���r���)r���r��Nra��r���kernelz^\s*\#\d+\s\[\w+\]\s(\w+)r��r���r��r��rq��z0x[0-9a-f]{6,}ADDRr��z%s:%sz.^(?:([\w:~]+).*|(<signal handler called>)\s*)$r���r��rE���z(\w+): r���r��z)^\s+File "([^"]+).*line (\d+).*\sin (.*)$r��z:%s@%sr��z(%s)_PythonExceptionQualifierr��r��suspendresumer��z:%szdmi.bios.versionr��Fr���zBUG: unable to handlez^BUG: unable to handle (.*) at z.could not parse expected problem type line: %szIP: z Call Trace:Tr���)rT���rj���r ��r��r���r���subr��r ���r"���islinkr��r���r`���r���rl���r���_extract_function_and_addressr���)r���sigregexr��r���r��linesr��loc_rer���exc_name in_trace_bodyr���parsedr��r���r���r���crash_signatured��s���                              zReport.crash_signaturec�����������������C���s>���t�d|}|r|d}|sJ�d|�|d�dkr|S�d�S�)Nz \[.*\] (.*)$r���z,could not parse expected call trace line: %sr���?)rT���rl���r���)r���r��r%��r��r���r���r���r����s���   z$Report._extract_function_and_addressc�����������������C���s��d|�vs d|�vs d|�vrdS�d|�d�v�rdS�g�}d}|�d���D�]:}|drR|�d�}|d s3q t|d }|d k�r=q |�|}|rN||d d �n|d7�}t|dkrZ�nq |dkrit||�dk�ridS�|dkrst|dk�s}|dkrt|dk�rdS�d|�d�|�d�d |f�S�)a��Compute heuristic duplicate signature for a signal crash. This should be used if crash_signature() fails, i. e. Stacktrace does not have enough symbols. This approach only uses addresses in the stack trace and does not rely on symbol resolution. As we can't unwind these stack traces, we cannot limit them to the top five frames and thus will end up with several or many different signatures for a particular crash. But these can be computed and synchronously checked with a crash database at the client side, which avoids having to upload and process the full report. So on the server-side crash database we will only have to deal with all the equivalence classes (i. e. same crash producing a number of possible signatures) instead of every single report. Return None when signature cannot be determined. r-��ra��r��NzErrno 13r���#r���0x���i���r��z..���r���r�����z%s:%s:%sr���) r ��r���r���r8��_address_to_offsetr���r'���r��r���)r���stackfailedr��addroffsetr���r���r���r����s<���       (z Report.crash_signature_addressesc����������� ��� ���C���s��g�}t��dkr\tt��}t|d�dkr(|tdt |d��df�|tdt |d��df�|d� dD�]}| �}t|dkr[|td t |�d f�q@t� �d �}t|dkrw|tdt |�d f�z|�d =�W�n �t y���Y�nw�|�D�]I}|do|dv}|sd|v�s|dv�rt|�|�dsq|D�])\}}t|�|�tkr|||�|�jdddd|�|<�q|||�|�|�|<�qqdS�)zRemove user identifying strings from the report. This particularly removes the user name, host name, and IPs from attributes which contain data read from the environment, and removes the ProcCwd attribute completely. r���r���z\b%s\busernamer��z/home/usernamer���,z (\b|\s)%s\bz \1User Namer���hostnamer��Proc) ProcCpuinfor-��r���ProcInterrupts ProcModulesra��)r�� PythonArgsTitle JournalErrorsisspacer&���r'���r(���N)r ���rC��r���r���r���r��r���rT���rj���r��r���r0���r���r`���r���rb��r���ri���r��r1���rd���) r��� replacementsr���r��r4��r�� is_proc_fieldrn���replr���r���r��� anonymize7��s<��� ""      &zReport.anonymizec�������������� ���C���s*��d|�v�sJ�|��d|�d�}d}d|�v�r|�d�t�krd}|r(tj|ddnd}td |}|s3d S�|g}d}|sKtd |} | rE| g}ntj d �|rd } |dd|�dd|�dd|�dd|| || f�g7�}|rd||| || |f�} d|�} | | d|| f�d}| dd|| f��|dd|�g7�}|d�|�}|dd|�g7�}d|�v�rt |�d�drt j dd\} }ttj|�t | |�d��t| �n?t |�d�d rt j dd\} }ttj|�t| �t|d!}|�d� |�W�d���n1�sw���Y��n|�d�d�}|dd"|�g7�}||fS�)#a"��Build gdb command for this report. This builds a gdb command for processing the given report, by setting the file to the ExecutablePath/InterpreterPath, unpacking the core dump and pointing "core-file" to it (if the report has a core dump), and setting up the paths when calling gdb in a package sandbox. When available, this calls "gdb-multiarch" instead of "gdb", for processing crash reports from foreign architectures. Return argv list for gdb and any environment variables. r���r��Fr���TusrbinNgdb)rE���rE���z gdb-multiarchzWARNING: Please install gdb-multiarch for processing reports from foreign architectures. Results with "gdb" will be very poor. zx86_64-linux-gnurt��z)set debug-file-directory %s/usr/lib/debugzset solib-absolute-prefix zadd-auto-load-safe-path z-set solib-search-path %s/lib/%s:%s/usr/lib/%sz)%s/lib:%s/lib/%s:%s/usr/lib/%s:%s/usr/libz%s/usrz%s/usr/lib/%s/gconv)LD_LIBRARY_PATH PYTHONHOME GCONV_PATHr���z%s/lib/%s/ld-linux-x86-64.so.2z#set data-directory %s/usr/share/gdbr��z file "%s"rm��r^�� apport_core_)prefix gzipvaluewbz core-file )r���r���r���r ���r"���r���r���sysrA���re��insertrb��rc��rd��atexitregisterrz���rf��r+���)r���sandboxr�� executable same_archgdb_sandbox_bingdb_pathrN���r���manative_multiarch ld_lib_pathpyhomer6���rj��r���r���r���r���r~��a��s���          zReport.gdb_commandc�����������������C���sB���|����|�jD�]\}}}||kr||krd|||�f���S�qdS�)a^��Resolve a memory address to an ELF name and offset. This can be used for building duplicate signatures from non-symbolic stack traces. These often do not have enough symbols available to resolve function names, but taking the raw addresses also is not suitable due to ASLR. But the offsets within a library should be constant between crashes (assuming the same version of all libraries). This needs and uses the "ProcMaps" field to resolve addresses. Return 'path+offset' when found, or None if address is not in any mapped range. z%s+%xN)_build_proc_maps_cacher���)r���r0��startendelfr���r���r���r-����s ���zReport._address_to_offsetc�����������������C���s���|�j�rdS�d|�v�s J�g�|�_�td}td}|�d��D�]4}|�s%q||}|s:||r2q|s:J�d|�|�j�t|ddt|dd|d f�qdS�) z_Generate self._proc_maps_cache from ProcMaps field. This only gets done once. Nr-��z-^([0-9a-fA-F]+)-([0-9a-fA-F]+).*\s{2,}(\S.*$)z ^([0-9a-fA-F]+)-([0-9a-fA-F]+)\szcannot parse ProcMaps line: r���r*��r���r��) r���rT���rj���r ��r0���r��r���r8��r���)r���fmt fmt_unknownr��r���r���r���r���rX����s$���     zReport._build_proc_maps_cachec�������������� ���C���s���t�s|durtjdtj|d}nd|�}zPt|6}|D�]!}|�}d|v�r>|dr>d|v�r>|ddd�dd �}�n q �W�d���W�dS�W�d���n1�sSw���Y��td |�j }W�||fS��t t fyp���Y�dS�w�) zGet logind session path and start time. Return (session_id, session_start_timestamp) if process is in a logind session, or None otherwise. Ncgroupr���z/proc/%s/cgroupz name=systemd:z.scopez /session-r���iz/run/systemd/sessions/) r���r ���r+���r,���r.���r0���r��r���rA��rB��r3���r2���)klassr#���r<��� cgroup_filer���r�� my_sessionsession_start_timer���r���r���rD����s(���   zReport.get_logind_session)r���Nr���NN)'__name__ __module__ __qualname____doc__r���r���r���r���r���r���r���r��r�� staticmethodr��rG��r?��rl��r��r��r��r��r��r��r��r��r��r��r��r��r&��r��r��r@��r~��r-��rX�� classmethodrD��r���r���r���r���r��� ��sN����   5+M  Z ; )m >;+-F. � �  > *Y r���rc��)?rg��rF���rc��os.pathr ���rT���r���r���r.���r���r��r���r;��rK��rM��importlib.utilr"��rA��xml.domrZ���xml.dom.minidomxml.parsers.expatr���r���r��� urllib.errorr���urllib.requestr��� urllib.parser���urllibr3���rf���r���apport.fileutilsapport.packaging_implr���r���apport.hookutilsr���r���r��� _data_dirr��r��r��r��r��r��r ��r���r$���r8���r?���rR���rs���ry���r|���r���r���r���r���r���r���r���r���<module>���sN����@ @            /