We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
r2: 'NoneType' object has no attribute 'cast' (<class 'AttributeError'>)
### Description


This happens when i initiate r2 after loading a binary in pwndbg 
I have tested both in  wsl and a 64bit ubuntu machine same behavior sorta 


### Steps to reproduce


1. Load a binary 
2. Run r2 
Exception occured: r2: 'NoneType' object has no attribute 'cast' (<class 'AttributeError'>)
Traceback (most recent call last):
  File "/root/reverse/pwndbg/pwndbg/commands/__init__.py", line 135, in __call__
    return self.function(*args, **kwargs)
  File "/root/reverse/pwndbg/pwndbg/commands/__init__.py", line 215, in _OnlyWithFile
    return function(*a, **kw)
  File "/root/reverse/pwndbg/pwndbg/commands/radare2.py", line 28, in r2
    addr = pwndbg.regs.pc
  File "/root/reverse/pwndbg/pwndbg/memoize.py", line 48, in __call__
    value = self.func(*args, **kwargs)
  File "/root/reverse/pwndbg/pwndbg/regs.py", line 280, in __getattr__
    value = value.cast(pwndbg.typeinfo.ptrdiff)
AttributeError: 'NoneType' object has no attribute 'cast'





### My setup


Gdb:      7.11.1
Python:   3.5.2 (default, Nov 12 2018, 13:43:14)  [GCC 5.4.0 20160609]
Pwndbg:   1.1.0 build: 054f209
Capstone: 4.0.1024
Unicorn:  1.0.1


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pwndbg/commands/radare2.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 
8 import argparse
9 import subprocess
10 
11 import pwndbg.commands
12 
13 parser = argparse.ArgumentParser(description='Launches radare2',
14                                  epilog="Example: r2 -- -S -AA")
15 parser.add_argument('--no-seek', action='store_true',
16                     help='Do not seek to current pc')
17 parser.add_argument('arguments', nargs='*', type=str,
18                     help='Arguments to pass to radare')
19 
20 
21 @pwndbg.commands.ArgparsedCommand(parser)
22 @pwndbg.commands.OnlyWithFile
23 def r2(arguments, no_seek=False):
24     filename = pwndbg.file.get_file(pwndbg.proc.exe)
25 
26     # Build up the command line to run
27     cmd = ['radare2', filename]
28     addr = pwndbg.regs.pc
29     if pwndbg.elf.get_elf_info(filename).is_pie:
30         addr -= pwndbg.elf.exe().address
31     if not no_seek and pwndbg.proc.alive:
32         cmd.extend(['-s', hex(addr)])
33     cmd += arguments
34 
35     try:
36         subprocess.call(cmd)
37     except Exception:
38         print("Could not run radare2. Please ensure it's installed and in $PATH.")
39
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pwndbg/commands/radare2.py b/pwndbg/commands/radare2.py
--- a/pwndbg/commands/radare2.py
+++ b/pwndbg/commands/radare2.py
@@ -25,11 +25,12 @@
 
     # Build up the command line to run
     cmd = ['radare2', filename]
-    addr = pwndbg.regs.pc
-    if pwndbg.elf.get_elf_info(filename).is_pie:
-        addr -= pwndbg.elf.exe().address
-    if not no_seek and pwndbg.proc.alive:
-        cmd.extend(['-s', hex(addr)])
+    if pwndbg.proc.alive:
+        addr = pwndbg.regs.pc
+        if pwndbg.elf.get_elf_info(filename).is_pie:
+            addr -= pwndbg.elf.exe().address
+        if not no_seek:
+            cmd.extend(['-s', hex(addr)])
     cmd += arguments
 
     try:

{"golden_diff": "diff --git a/pwndbg/commands/radare2.py b/pwndbg/commands/radare2.py\n--- a/pwndbg/commands/radare2.py\n+++ b/pwndbg/commands/radare2.py\n@@ -25,11 +25,12 @@\n \n     # Build up the command line to run\n     cmd = ['radare2', filename]\n-    addr = pwndbg.regs.pc\n-    if pwndbg.elf.get_elf_info(filename).is_pie:\n-        addr -= pwndbg.elf.exe().address\n-    if not no_seek and pwndbg.proc.alive:\n-        cmd.extend(['-s', hex(addr)])\n+    if pwndbg.proc.alive:\n+        addr = pwndbg.regs.pc\n+        if pwndbg.elf.get_elf_info(filename).is_pie:\n+            addr -= pwndbg.elf.exe().address\n+        if not no_seek:\n+            cmd.extend(['-s', hex(addr)])\n     cmd += arguments\n \n     try:\n", "issue": "r2: 'NoneType' object has no attribute 'cast' (<class 'AttributeError'>)\n### Description\r\n\r\n\r\nThis happens when i initiate r2 after loading a binary in pwndbg \r\nI have tested both in  wsl and a 64bit ubuntu machine same behavior sorta \r\n\r\n\r\n### Steps to reproduce\r\n\r\n\r\n1. Load a binary \r\n2. Run r2 \r\nException occured: r2: 'NoneType' object has no attribute 'cast' (<class 'AttributeError'>)\r\nTraceback (most recent call last):\r\n  File \"/root/reverse/pwndbg/pwndbg/commands/__init__.py\", line 135, in __call__\r\n    return self.function(*args, **kwargs)\r\n  File \"/root/reverse/pwndbg/pwndbg/commands/__init__.py\", line 215, in _OnlyWithFile\r\n    return function(*a, **kw)\r\n  File \"/root/reverse/pwndbg/pwndbg/commands/radare2.py\", line 28, in r2\r\n    addr = pwndbg.regs.pc\r\n  File \"/root/reverse/pwndbg/pwndbg/memoize.py\", line 48, in __call__\r\n    value = self.func(*args, **kwargs)\r\n  File \"/root/reverse/pwndbg/pwndbg/regs.py\", line 280, in __getattr__\r\n    value = value.cast(pwndbg.typeinfo.ptrdiff)\r\nAttributeError: 'NoneType' object has no attribute 'cast'\r\n\r\n\r\n\r\n\r\n\r\n### My setup\r\n\r\n\r\nGdb:      7.11.1\r\nPython:   3.5.2 (default, Nov 12 2018, 13:43:14)  [GCC 5.4.0 20160609]\r\nPwndbg:   1.1.0 build: 054f209\r\nCapstone: 4.0.1024\r\nUnicorn:  1.0.1\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport argparse\nimport subprocess\n\nimport pwndbg.commands\n\nparser = argparse.ArgumentParser(description='Launches radare2',\n                                 epilog=\"Example: r2 -- -S -AA\")\nparser.add_argument('--no-seek', action='store_true',\n                    help='Do not seek to current pc')\nparser.add_argument('arguments', nargs='*', type=str,\n                    help='Arguments to pass to radare')\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWithFile\ndef r2(arguments, no_seek=False):\n    filename = pwndbg.file.get_file(pwndbg.proc.exe)\n\n    # Build up the command line to run\n    cmd = ['radare2', filename]\n    addr = pwndbg.regs.pc\n    if pwndbg.elf.get_elf_info(filename).is_pie:\n        addr -= pwndbg.elf.exe().address\n    if not no_seek and pwndbg.proc.alive:\n        cmd.extend(['-s', hex(addr)])\n    cmd += arguments\n\n    try:\n        subprocess.call(cmd)\n    except Exception:\n        print(\"Could not run radare2. Please ensure it's installed and in $PATH.\")\n", "path": "pwndbg/commands/radare2.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport argparse\nimport subprocess\n\nimport pwndbg.commands\n\nparser = argparse.ArgumentParser(description='Launches radare2',\n                                 epilog=\"Example: r2 -- -S -AA\")\nparser.add_argument('--no-seek', action='store_true',\n                    help='Do not seek to current pc')\nparser.add_argument('arguments', nargs='*', type=str,\n                    help='Arguments to pass to radare')\n\n\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWithFile\ndef r2(arguments, no_seek=False):\n    filename = pwndbg.file.get_file(pwndbg.proc.exe)\n\n    # Build up the command line to run\n    cmd = ['radare2', filename]\n    if pwndbg.proc.alive:\n        addr = pwndbg.regs.pc\n        if pwndbg.elf.get_elf_info(filename).is_pie:\n            addr -= pwndbg.elf.exe().address\n        if not no_seek:\n            cmd.extend(['-s', hex(addr)])\n    cmd += arguments\n\n    try:\n        subprocess.call(cmd)\n    except Exception:\n        print(\"Could not run radare2. Please ensure it's installed and in $PATH.\")\n", "path": "pwndbg/commands/radare2.py"}]}