prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  TypeError exception raised on up/down commands.
  ### Description
  
  When running the command `up` or `down` with an integer argument, the following exception is raised:
  
  ```
  Traceback (most recent call last):
    File "/home/david/.pwndbg/pwndbg/commands/__init__.py", line 109, in __call__
      return self.function(*args, **kwargs)
    File "/home/david/.pwndbg/pwndbg/commands/__init__.py", line 200, in _OnlyWhenRunning
      return function(*a, **kw)
    File "/home/david/.pwndbg/pwndbg/commands/ida.py", line 46, in up
      for i in range(n):
  TypeError: 'str' object cannot be interpreted as an integer
  ```
  
  ### Steps to reproduce
  
  Open any binary and attempt to do `up 2` during debugging.
  
  ### My setup
  
  pwndbg> version
  Gdb:      7.12.0.20161007-git
  Python:   3.6.5rc1 (default, Mar 14 2018, 06:54:23)  [GCC 7.3.0]
  Pwndbg:   1.0.0 build: f69b81e
  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/ida.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 bz2
  9 import datetime
  10 import os
  11 
  12 import gdb
  13 
  14 import pwndbg.commands
  15 import pwndbg.commands.context
  16 import pwndbg.ida
  17 import pwndbg.regs
  18 from pwndbg.gdbutils.functions import GdbFunction
  19 
  20 
  21 @pwndbg.commands.ParsedCommand
  22 @pwndbg.commands.OnlyWhenRunning
  23 @pwndbg.events.stop
  24 @pwndbg.ida.withIDA
  25 def j(*args):
  26     """
  27     Synchronize IDA's cursor with GDB
  28     """
  29     try:
  30         pc = int(gdb.selected_frame().pc())
  31         pwndbg.ida.Jump(pc)
  32     except Exception:
  33         pass
  34 
  35 
  36 
  37 @pwndbg.commands.Command
  38 @pwndbg.commands.OnlyWhenRunning
  39 def up(n=1):
  40     """
  41     Select and print stack frame that called this one.
  42     An argument says how many frames up to go.
  43     """
  44     f = gdb.selected_frame()
  45 
  46     for i in range(n):
  47         o = f.older()
  48         if o:
  49             o.select()
  50 
  51     bt = pwndbg.commands.context.context_backtrace(with_banner=False)
  52     print('\n'.join(bt))
  53 
  54     j()
  55 
  56 
  57 @pwndbg.commands.Command
  58 @pwndbg.commands.OnlyWhenRunning
  59 def down(n=1):
  60     """
  61     Select and print stack frame called by this one.
  62     An argument says how many frames down to go.
  63     """
  64     f = gdb.selected_frame()
  65 
  66     for i in range(n):
  67         o = f.newer()
  68         if o:
  69             o.select()
  70 
  71     bt = pwndbg.commands.context.context_backtrace(with_banner=False)
  72     print('\n'.join(bt))
  73 
  74     j()
  75 
  76 
  77 @pwndbg.commands.Command
  78 @pwndbg.ida.withIDA
  79 def save_ida():
  80     """Save the IDA database"""
  81     if not pwndbg.ida.available():
  82         return
  83 
  84     path = pwndbg.ida.GetIdbPath()
  85 
  86     # Need to handle emulated paths for Wine
  87     if path.startswith('Z:'):
  88         path = path[2:].replace('\\', '/')
  89         pwndbg.ida.SaveBase(path)
  90 
  91     basename = os.path.basename(path)
  92     dirname = os.path.dirname(path)
  93     backups = os.path.join(dirname, 'ida-backup')
  94 
  95     if not os.path.isdir(backups):
  96         os.mkdir(backups)
  97 
  98     basename, ext = os.path.splitext(basename)
  99     basename += '-%s' % datetime.datetime.now().isoformat()
  100     basename += ext
  101 
  102     # Windows doesn't like colons in paths
  103     basename = basename.replace(':', '_')
  104 
  105     full_path = os.path.join(backups, basename)
  106 
  107     pwndbg.ida.SaveBase(full_path)
  108 
  109     data = open(full_path, 'rb').read()
  110 
  111     # Compress!
  112     full_path_compressed = full_path + '.bz2'
  113     bz2.BZ2File(full_path_compressed, 'w').write(data)
  114 
  115     # Remove old version
  116     os.unlink(full_path)
  117 
  118 save_ida()
  119 
  120 
  121 @GdbFunction()
  122 def ida(name):
  123 
  124     """Evaluate ida.LocByName() on the supplied value."""
  125     name = name.string()
  126     result = pwndbg.ida.LocByName(name)
  127 
  128     if 0xffffe000 <= result <= 0xffffffff or 0xffffffffffffe000 <= result <= 0xffffffffffffffff:
  129         raise ValueError("ida.LocByName(%r) == BADADDR" % name)
  130 
  131     return result
  132
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/pwndbg/commands/ida.py b/pwndbg/commands/ida.py
  --- a/pwndbg/commands/ida.py
  +++ b/pwndbg/commands/ida.py
  @@ -43,10 +43,10 @@
       """
       f = gdb.selected_frame()
   
  -    for i in range(n):
  -        o = f.older()
  -        if o:
  -            o.select()
  +    for i in range(int(n)):
  +        if f.older():
  +            f = f.older()
  +    f.select()
   
       bt = pwndbg.commands.context.context_backtrace(with_banner=False)
       print('\n'.join(bt))
  @@ -63,10 +63,10 @@
       """
       f = gdb.selected_frame()
   
  -    for i in range(n):
  -        o = f.newer()
  -        if o:
  -            o.select()
  +    for i in range(int(n)):
  +        if f.newer():
  +            f = f.newer()
  +    f.select()
   
       bt = pwndbg.commands.context.context_backtrace(with_banner=False)
       print('\n'.join(bt))
  
verification_info: {"golden_diff": "diff --git a/pwndbg/commands/ida.py b/pwndbg/commands/ida.py\n--- a/pwndbg/commands/ida.py\n+++ b/pwndbg/commands/ida.py\n@@ -43,10 +43,10 @@\n     \"\"\"\n     f = gdb.selected_frame()\n \n-    for i in range(n):\n-        o = f.older()\n-        if o:\n-            o.select()\n+    for i in range(int(n)):\n+        if f.older():\n+            f = f.older()\n+    f.select()\n \n     bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n     print('\\n'.join(bt))\n@@ -63,10 +63,10 @@\n     \"\"\"\n     f = gdb.selected_frame()\n \n-    for i in range(n):\n-        o = f.newer()\n-        if o:\n-            o.select()\n+    for i in range(int(n)):\n+        if f.newer():\n+            f = f.newer()\n+    f.select()\n \n     bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n     print('\\n'.join(bt))\n", "issue": "TypeError exception raised on up/down commands.\n### Description\r\n\r\nWhen running the command `up` or `down` with an integer argument, the following exception is raised:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/david/.pwndbg/pwndbg/commands/__init__.py\", line 109, in __call__\r\n    return self.function(*args, **kwargs)\r\n  File \"/home/david/.pwndbg/pwndbg/commands/__init__.py\", line 200, in _OnlyWhenRunning\r\n    return function(*a, **kw)\r\n  File \"/home/david/.pwndbg/pwndbg/commands/ida.py\", line 46, in up\r\n    for i in range(n):\r\nTypeError: 'str' object cannot be interpreted as an integer\r\n```\r\n\r\n### Steps to reproduce\r\n\r\nOpen any binary and attempt to do `up 2` during debugging.\r\n\r\n### My setup\r\n\r\npwndbg> version\r\nGdb:      7.12.0.20161007-git\r\nPython:   3.6.5rc1 (default, Mar 14 2018, 06:54:23)  [GCC 7.3.0]\r\nPwndbg:   1.0.0 build: f69b81e\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 bz2\nimport datetime\nimport os\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.commands.context\nimport pwndbg.ida\nimport pwndbg.regs\nfrom pwndbg.gdbutils.functions import GdbFunction\n\n\n@pwndbg.commands.ParsedCommand\n@pwndbg.commands.OnlyWhenRunning\n@pwndbg.events.stop\n@pwndbg.ida.withIDA\ndef j(*args):\n    \"\"\"\n    Synchronize IDA's cursor with GDB\n    \"\"\"\n    try:\n        pc = int(gdb.selected_frame().pc())\n        pwndbg.ida.Jump(pc)\n    except Exception:\n        pass\n\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWhenRunning\ndef up(n=1):\n    \"\"\"\n    Select and print stack frame that called this one.\n    An argument says how many frames up to go.\n    \"\"\"\n    f = gdb.selected_frame()\n\n    for i in range(n):\n        o = f.older()\n        if o:\n            o.select()\n\n    bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n    print('\\n'.join(bt))\n\n    j()\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWhenRunning\ndef down(n=1):\n    \"\"\"\n    Select and print stack frame called by this one.\n    An argument says how many frames down to go.\n    \"\"\"\n    f = gdb.selected_frame()\n\n    for i in range(n):\n        o = f.newer()\n        if o:\n            o.select()\n\n    bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n    print('\\n'.join(bt))\n\n    j()\n\n\n@pwndbg.commands.Command\n@pwndbg.ida.withIDA\ndef save_ida():\n    \"\"\"Save the IDA database\"\"\"\n    if not pwndbg.ida.available():\n        return\n\n    path = pwndbg.ida.GetIdbPath()\n\n    # Need to handle emulated paths for Wine\n    if path.startswith('Z:'):\n        path = path[2:].replace('\\\\', '/')\n        pwndbg.ida.SaveBase(path)\n\n    basename = os.path.basename(path)\n    dirname = os.path.dirname(path)\n    backups = os.path.join(dirname, 'ida-backup')\n\n    if not os.path.isdir(backups):\n        os.mkdir(backups)\n\n    basename, ext = os.path.splitext(basename)\n    basename += '-%s' % datetime.datetime.now().isoformat()\n    basename += ext\n\n    # Windows doesn't like colons in paths\n    basename = basename.replace(':', '_')\n\n    full_path = os.path.join(backups, basename)\n\n    pwndbg.ida.SaveBase(full_path)\n\n    data = open(full_path, 'rb').read()\n\n    # Compress!\n    full_path_compressed = full_path + '.bz2'\n    bz2.BZ2File(full_path_compressed, 'w').write(data)\n\n    # Remove old version\n    os.unlink(full_path)\n\nsave_ida()\n\n\n@GdbFunction()\ndef ida(name):\n\n    \"\"\"Evaluate ida.LocByName() on the supplied value.\"\"\"\n    name = name.string()\n    result = pwndbg.ida.LocByName(name)\n\n    if 0xffffe000 <= result <= 0xffffffff or 0xffffffffffffe000 <= result <= 0xffffffffffffffff:\n        raise ValueError(\"ida.LocByName(%r) == BADADDR\" % name)\n\n    return result\n", "path": "pwndbg/commands/ida.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 bz2\nimport datetime\nimport os\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.commands.context\nimport pwndbg.ida\nimport pwndbg.regs\nfrom pwndbg.gdbutils.functions import GdbFunction\n\n\n@pwndbg.commands.ParsedCommand\n@pwndbg.commands.OnlyWhenRunning\n@pwndbg.events.stop\n@pwndbg.ida.withIDA\ndef j(*args):\n    \"\"\"\n    Synchronize IDA's cursor with GDB\n    \"\"\"\n    try:\n        pc = int(gdb.selected_frame().pc())\n        pwndbg.ida.Jump(pc)\n    except Exception:\n        pass\n\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWhenRunning\ndef up(n=1):\n    \"\"\"\n    Select and print stack frame that called this one.\n    An argument says how many frames up to go.\n    \"\"\"\n    f = gdb.selected_frame()\n\n    for i in range(int(n)):\n        if f.older():\n            f = f.older()\n    f.select()\n\n    bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n    print('\\n'.join(bt))\n\n    j()\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWhenRunning\ndef down(n=1):\n    \"\"\"\n    Select and print stack frame called by this one.\n    An argument says how many frames down to go.\n    \"\"\"\n    f = gdb.selected_frame()\n\n    for i in range(int(n)):\n        if f.newer():\n            f = f.newer()\n    f.select()\n\n    bt = pwndbg.commands.context.context_backtrace(with_banner=False)\n    print('\\n'.join(bt))\n\n    j()\n\n\n@pwndbg.commands.Command\n@pwndbg.ida.withIDA\ndef save_ida():\n    \"\"\"Save the IDA database\"\"\"\n    if not pwndbg.ida.available():\n        return\n\n    path = pwndbg.ida.GetIdbPath()\n\n    # Need to handle emulated paths for Wine\n    if path.startswith('Z:'):\n        path = path[2:].replace('\\\\', '/')\n        pwndbg.ida.SaveBase(path)\n\n    basename = os.path.basename(path)\n    dirname = os.path.dirname(path)\n    backups = os.path.join(dirname, 'ida-backup')\n\n    if not os.path.isdir(backups):\n        os.mkdir(backups)\n\n    basename, ext = os.path.splitext(basename)\n    basename += '-%s' % datetime.datetime.now().isoformat()\n    basename += ext\n\n    # Windows doesn't like colons in paths\n    basename = basename.replace(':', '_')\n\n    full_path = os.path.join(backups, basename)\n\n    pwndbg.ida.SaveBase(full_path)\n\n    data = open(full_path, 'rb').read()\n\n    # Compress!\n    full_path_compressed = full_path + '.bz2'\n    bz2.BZ2File(full_path_compressed, 'w').write(data)\n\n    # Remove old version\n    os.unlink(full_path)\n\nsave_ida()\n\n\n@GdbFunction()\ndef ida(name):\n\n    \"\"\"Evaluate ida.LocByName() on the supplied value.\"\"\"\n    name = name.string()\n    result = pwndbg.ida.LocByName(name)\n\n    if 0xffffe000 <= result <= 0xffffffff or 0xffffffffffffe000 <= result <= 0xffffffffffffffff:\n        raise ValueError(\"ida.LocByName(%r) == BADADDR\" % name)\n\n    return result\n", "path": "pwndbg/commands/ida.py"}]}