prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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
  
  
  </issue>
  <code>
  [start of pwndbg/commands/radare2.py]
  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 of pwndbg/commands/radare2.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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:
  
verification_info: {"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"}]}