Repository: angr/angr

Issue:
SimSegFaultException cannot be pickled
<!--
*Disclaimer:
The angr suite is maintained by a small team of volunteers.
While we cannot guarantee any timeliness for fixes and enhancements, we will do our best.
For more real-time help with angr, from us and the community, join our [Slack.](http://angr.io/invite/)*
-->
---

**Describe the bug.**
<!--
Please include a clear and concise description of what the bug is.
-->
SimSegFaultException cannot be pickled.  This prevents simgrs from being pickled too when they contain an instance of this error.


**Environment Information.**
<!--
Many common issues are caused by problems with the local Python environment.
Before submitting, double-check that your versions of all modules in the angr suite (angr, cle, pyvex, ...) are up to date.
Please include the output of `python -m angr.misc.bug_report` here.
-->
```
angr environment report
=============================
Date: 2020-03-05 09:52:23.315348
Running in virtual environment at /home/ed/.virtualenvs/angr
Platform: linux-x86_64
Python version: 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0]
######## angr #########
Python found it in /home/ed/Documents/angr-dev/angr/angr
Pip version angr 8.20.1.7
Git info:
	Current commit 6c7630ce125442e3492d59831e3e8ac9e5e19217 from branch master
	Checked out from remote origin: https://github.com/angr/angr
######## ailment #########
Python found it in /home/ed/Documents/angr-dev/ailment/ailment
Pip version ailment 8.20.1.7
Git info:
	Current commit c696edc9f31ecccaaa36b1e40ca1bed6c9715242 from branch master
	Checked out from remote origin: https://github.com/angr/ailment
######## cle #########
Python found it in /home/ed/Documents/angr-dev/cle/cle
Pip version cle 8.20.1.7
Git info:
	Current commit 577164e52c663e479fa684be9118543b4652f3d3 from branch master
	Checked out from remote origin: https://github.com/angr/cle
######## pyvex #########
Python found it in /home/ed/Documents/angr-dev/pyvex/pyvex
Pip version pyvex 8.20.1.7
Git info:
	Current commit f4753f85a8c18dae9dbb32301f8a7804efd36491 from branch master
	Checked out from remote origin: https://github.com/angr/pyvex
######## claripy #########
Python found it in /home/ed/Documents/angr-dev/claripy/claripy
Pip version claripy 8.20.1.7
Git info:
	Current commit b6eabc37aed7c2989faf12406a247004b5849216 from branch master
	Checked out from remote origin: https://github.com/angr/claripy
######## archinfo #########
Python found it in /home/ed/Documents/angr-dev/archinfo/archinfo
Pip version archinfo 8.20.1.7
Git info:
	Current commit 1db8e3c200e9346b2902b9d929bbd2676113b72e from branch master
	Checked out from remote origin: https://github.com/angr/archinfo
######## z3 #########
Python found it in /home/ed/.virtualenvs/angr/lib/python3.6/site-packages/z3
Pip version z3-solver 4.8.7.0
Couldn't find git info
######## unicorn #########
Python found it in /home/ed/.virtualenvs/angr/lib/python3.6/site-packages/unicorn
Pip version unicorn 1.0.1
Couldn't find git info
######### Native Module Info ##########
angr: <CDLL '/home/ed/Documents/angr-dev/angr/angr/lib/angr_native.so', handle 3697340 at 0x7f987cec4198>
unicorn: <CDLL '/home/ed/.virtualenvs/angr/lib/python3.6/site-packages/unicorn/lib/libunicorn.so', handle 2df4070 at 0x7f9882cc6b38>
pyvex: <cffi.api._make_ffi_library.<locals>.FFILibrary object at 0x7f9883c4d8d0>
z3: <CDLL '/home/ed/.virtualenvs/angr/lib/python3.6/site-packages/z3/lib/libz3.so', handle 301a620 at 0x7f9880b15978>
```

**To Reproduce.**
<!--
Please include *both a script to reproduce the crash, and attach the binary used, if possible*
-->
``` python
#!/usr/bin/env python

import angr
import pickle

ex = angr.errors.SimSegfaultException(42, "why not?")
pickle.loads(pickle.dumps(ex))
```


**Additional context.**
<!--
Add any other context about the problem here.
-->



Discussion:

Resolving patch:
diff --git a/angr/errors.py b/angr/errors.py
--- a/angr/errors.py
+++ b/angr/errors.py
@@ -280,6 +280,9 @@ def __init__(self, expr_type, expr):
     def __repr__(self):
         return "SimUninitializedAccessError (expr %s is used as %s)" % (self.expr, self.expr_type)
 
+    def __reduce__(self):
+        return (SimUninitializedAccessError, (self.expr_type, self.expr))
+
 #
 # SimIRStmt errors
 #
@@ -411,6 +414,9 @@ def __repr__(self):
             (', original %s' % self.original_addr.__repr__(max_depth=3)) if self.original_addr is not None else ''
         )
 
+    def __reduce__(self):
+        return (SimSegfaultException, (self.addr, self.reason, self.original_addr))
+
 SimSegfaultError = SimSegfaultException
 
 class SimZeroDivisionException(SimException, SimOperationError):


Test patch: