We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Broken `entry` command
### Description

The `entry` command pass arguments differently then the `run` command.

### Steps to reproduce

```
[dc@dc:pwndbg|dev *$%]$ gdb python
Loaded 113 commands. Type pwndbg [filter] for a list.
Reading symbols from python...(no debugging symbols found)...done.
pwndbg> set exception-verbose on
Set whether to print a full stacktracefor exceptions raised in Pwndbg commands to True
pwndbg> run -c "print(1); print(2)"
Starting program: /usr/bin/python -c "print(1); print(2)"
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
1
2
[Inferior 1 (process 20590) exited normally]
pwndbg> entry -c "print(1); print(2)"
('-c', 'print(1); print(2)')
Running '%s' run -c print(1); print(2)
/bin/bash: -c: line 0: syntax error near unexpected token `('
/bin/bash: -c: line 0: `exec /usr/bin/python -c print(1); print(2)'
Traceback (most recent call last):
  File "/home/dc/installed/pwndbg/pwndbg/commands/__init__.py", line 100, in __call__
    return self.function(*args, **kwargs)
  File "/home/dc/installed/pwndbg/pwndbg/commands/__init__.py", line 181, in _OnlyWithFile
    return function(*a, **kw)
  File "/home/dc/installed/pwndbg/pwndbg/commands/start.py", line 72, in entry
    gdb.execute(run, from_tty=False)
gdb.error: During startup program exited with code 1.

If that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues
(Please don't forget to search if it hasn't been reported before)
PS: Pull requests are welcome
```

### My version

```
pwndbg> version
Gdb: GNU gdb (GDB) 8.0.1
Python: 3.6.3 (default, Oct 24 2017, 14:48:20)  [GCC 7.2.0]
Pwndbg: 1.0.0 build: 5811010
```

--- 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/start.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Launches the target process after setting a breakpoint at a convenient
5 entry point.
6 """
7 from __future__ import absolute_import
8 from __future__ import division
9 from __future__ import print_function
10 from __future__ import unicode_literals
11 
12 import gdb
13 
14 import pwndbg.commands
15 import pwndbg.elf
16 import pwndbg.events
17 import pwndbg.symbol
18 
19 break_on_first_instruction = False
20 
21 
22 @pwndbg.events.start
23 def on_start():
24     global break_on_first_instruction
25     if break_on_first_instruction:
26         spec = "*%#x" % (int(pwndbg.elf.entry()))
27         gdb.Breakpoint(spec, temporary=True)
28         break_on_first_instruction = False
29 
30 
31 @pwndbg.commands.Command
32 def start(*a):
33     """
34     Set a breakpoint at a convenient location in the binary,
35     generally 'main', 'init', or the entry point.
36     """
37     run = 'run ' + ' '.join(a)
38 
39     symbols = ["main",
40                 "_main",
41                 "start",
42                 "_start",
43                 "init",
44                 "_init"]
45 
46     for symbol in symbols:
47         address = pwndbg.symbol.address(symbol)
48 
49         if not address:
50             continue
51 
52         b = gdb.Breakpoint(symbol, temporary=True)
53         gdb.execute(run, from_tty=False, to_string=True)
54         return
55 
56     # Try a breakpoint at the binary entry
57     entry(*a)
58 
59 
60 @pwndbg.commands.Command
61 @pwndbg.commands.OnlyWithFile
62 def entry(*a):
63     """
64     Set a breakpoint at the first instruction executed in
65     the target binary.
66     """
67     global break_on_first_instruction
68     break_on_first_instruction = True
69     run = 'run ' + ' '.join(a)
70     gdb.execute(run, from_tty=False)
71
```

Path: `pwndbg/prompt.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 gdb
9 
10 import pwndbg.events
11 import pwndbg.memoize
12 
13 hint_msg = 'Loaded %i commands. Type pwndbg [filter] for a list.' % len(pwndbg.commands.Command.commands)
14 
15 print(pwndbg.color.red(hint_msg))
16 cur = (gdb.selected_inferior(), gdb.selected_thread())
17 
18 
19 def prompt_hook(*a):
20     global cur
21     new = (gdb.selected_inferior(), gdb.selected_thread())
22 
23     if cur != new:
24         pwndbg.events.after_reload(start=False)
25         cur = new
26 
27     if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:
28         prompt_hook_on_stop(*a)
29 
30 
31 @pwndbg.memoize.reset_on_stop
32 def prompt_hook_on_stop(*a):
33     pwndbg.commands.context.context()
34 
35 
36 gdb.prompt_hook = prompt_hook
37
```

Path: `pwndbg/dt.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Prints structures in a manner similar to Windbg's "dt" command.
5 """
6 from __future__ import absolute_import
7 from __future__ import division
8 from __future__ import print_function
9 from __future__ import unicode_literals
10 
11 import glob
12 import os
13 import re
14 import subprocess
15 import tempfile
16 
17 import gdb
18 
19 import pwndbg.memory
20 import pwndbg.typeinfo
21 
22 
23 def get_type(v):
24     t = v.type
25     while not t.name:
26         if t.code == gdb.TYPE_CODE_PTR:
27             t = t.target()
28     return t.name
29 
30 def get_typename(t):
31     return(str(t))
32 
33 def get_arrsize(f):
34     t = f.type
35     if t.code != gdb.TYPE_CODE_ARRAY:
36         return 0
37     t2 = t.target()
38     s  = t2.sizeof
39     return int(t.sizeof / t2.sizeof)
40 
41 def get_field_by_name(obj, field):
42     # Dereference once
43     if obj.type.code == gdb.TYPE_CODE_PTR:
44         obj = obj.dereference()
45     for f in re.split('(->|\.|\[\d+\])', field):
46         if not f: continue
47         if f   == '->':
48             obj = obj.dereference()
49         elif f == '.':
50             pass
51         elif f.startswith('['):
52             n   = int(f.strip('[]'))
53             obj = obj.cast(obj.dereference().type.pointer())
54             obj += n
55             obj = obj.dereference()
56         else:
57             obj = obj[f]
58     return obj
59 
60 def happy(typename):
61     prefix = ''
62     if 'unsigned' in typename:
63         prefix = 'u'
64         typename = typename.replace('unsigned ', '')
65     return prefix + {
66     'char': 'char',
67     'short int': 'short',
68     'long int': 'long',
69     'int': 'int',
70     'long long': 'longlong',
71     'float': 'float',
72     'double': 'double'
73     }[typename]
74 
75 def dt(name='', addr=None, obj = None):
76     """
77     Dump out a structure type Windbg style.
78     """
79     # Return value is a list of strings.of
80     # We concatenate at the end.
81     rv  = []
82 
83     if obj and not name:
84         t = obj.type
85         while t.code == (gdb.TYPE_CODE_PTR):
86             t   = t.target()
87             obj = obj.dereference()
88         name = str(t)
89 
90     # Lookup the type name specified by the user
91     else:
92         t = pwndbg.typeinfo.load(name)
93 
94     # If it's not a struct (e.g. int or char*), bail
95     if t.code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_TYPEDEF, gdb.TYPE_CODE_UNION):
96         raise Exception("Not a structure: %s" % t)
97 
98     # If an address was specified, create a Value of the
99     # specified type at that address.
100     if addr is not None:
101         obj = pwndbg.memory.poi(t, addr)
102 
103     # Header, optionally include the name
104     header = name
105     if obj: header = "%s @ %s" % (header, hex(int(obj.address)))
106     rv.append(header)
107 
108     if t.strip_typedefs().code == gdb.TYPE_CODE_ARRAY:
109         return "Arrays not supported yet"
110     if t.strip_typedefs().code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):
111         t = {name: obj or gdb.Value(0).cast(t)}
112 
113     for name, field in t.items():
114         # Offset into the parent structure
115         o     = getattr(field, 'bitpos', 0)/8
116         extra = str(field.type)
117         ftype = field.type.strip_typedefs()
118 
119         if obj and obj.type.strip_typedefs().code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):
120             v  = obj[name]
121 
122             if ftype.code == gdb.TYPE_CODE_INT:
123                 v = hex(int(v))
124             if ftype.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY) \
125                 and ftype.target() == pwndbg.typeinfo.uchar:
126                 data = pwndbg.memory.read(v.address, ftype.sizeof)
127                 v = ' '.join('%02x' % b for b in data)
128 
129             extra = v
130 
131         # Adjust trailing lines in 'extra' to line up
132         # This is necessary when there are nested structures.
133         # Ideally we'd expand recursively if the type is complex.
134         extra_lines = []
135         for i, line in enumerate(str(extra).splitlines()):
136             if i == 0: extra_lines.append(line)
137             else:      extra_lines.append(35*' ' + line)
138         extra = '\n'.join(extra_lines)
139 
140         line  = "    +0x%04x %-20s : %s" % (o, name, extra)
141         rv.append(line)
142 
143     return ('\n'.join(rv))
144
```
--- 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/start.py b/pwndbg/commands/start.py
--- a/pwndbg/commands/start.py
+++ b/pwndbg/commands/start.py
@@ -9,6 +9,8 @@
 from __future__ import print_function
 from __future__ import unicode_literals
 
+import shlex
+
 import gdb
 
 import pwndbg.commands
@@ -66,5 +68,5 @@
     """
     global break_on_first_instruction
     break_on_first_instruction = True
-    run = 'run ' + ' '.join(a)
+    run = 'run ' + ' '.join(map(shlex.quote, a))
     gdb.execute(run, from_tty=False)
diff --git a/pwndbg/dt.py b/pwndbg/dt.py
--- a/pwndbg/dt.py
+++ b/pwndbg/dt.py
@@ -112,7 +112,8 @@
 
     for name, field in t.items():
         # Offset into the parent structure
-        o     = getattr(field, 'bitpos', 0)/8
+        o     = getattr(field, 'bitpos', 0) // 8
+        b     = getattr(field, 'bitpos', 0) % 8
         extra = str(field.type)
         ftype = field.type.strip_typedefs()
 
@@ -137,7 +138,9 @@
             else:      extra_lines.append(35*' ' + line)
         extra = '\n'.join(extra_lines)
 
-        line  = "    +0x%04x %-20s : %s" % (o, name, extra)
+        bitpos = '' if not b else ('.%i' % b)
+
+        line  = "    +0x%04x%s %-20s : %s" % (o, bitpos, name, extra)
         rv.append(line)
 
     return ('\n'.join(rv))
diff --git a/pwndbg/prompt.py b/pwndbg/prompt.py
--- a/pwndbg/prompt.py
+++ b/pwndbg/prompt.py
@@ -33,4 +33,5 @@
     pwndbg.commands.context.context()
 
 
+
 gdb.prompt_hook = prompt_hook

{"golden_diff": "diff --git a/pwndbg/commands/start.py b/pwndbg/commands/start.py\n--- a/pwndbg/commands/start.py\n+++ b/pwndbg/commands/start.py\n@@ -9,6 +9,8 @@\n from __future__ import print_function\n from __future__ import unicode_literals\n \n+import shlex\n+\n import gdb\n \n import pwndbg.commands\n@@ -66,5 +68,5 @@\n     \"\"\"\n     global break_on_first_instruction\n     break_on_first_instruction = True\n-    run = 'run ' + ' '.join(a)\n+    run = 'run ' + ' '.join(map(shlex.quote, a))\n     gdb.execute(run, from_tty=False)\ndiff --git a/pwndbg/dt.py b/pwndbg/dt.py\n--- a/pwndbg/dt.py\n+++ b/pwndbg/dt.py\n@@ -112,7 +112,8 @@\n \n     for name, field in t.items():\n         # Offset into the parent structure\n-        o     = getattr(field, 'bitpos', 0)/8\n+        o     = getattr(field, 'bitpos', 0) // 8\n+        b     = getattr(field, 'bitpos', 0) % 8\n         extra = str(field.type)\n         ftype = field.type.strip_typedefs()\n \n@@ -137,7 +138,9 @@\n             else:      extra_lines.append(35*' ' + line)\n         extra = '\\n'.join(extra_lines)\n \n-        line  = \"    +0x%04x %-20s : %s\" % (o, name, extra)\n+        bitpos = '' if not b else ('.%i' % b)\n+\n+        line  = \"    +0x%04x%s %-20s : %s\" % (o, bitpos, name, extra)\n         rv.append(line)\n \n     return ('\\n'.join(rv))\ndiff --git a/pwndbg/prompt.py b/pwndbg/prompt.py\n--- a/pwndbg/prompt.py\n+++ b/pwndbg/prompt.py\n@@ -33,4 +33,5 @@\n     pwndbg.commands.context.context()\n \n \n+\n gdb.prompt_hook = prompt_hook\n", "issue": "Broken `entry` command\n### Description\r\n\r\nThe `entry` command pass arguments differently then the `run` command.\r\n\r\n### Steps to reproduce\r\n\r\n```\r\n[dc@dc:pwndbg|dev *$%]$ gdb python\r\nLoaded 113 commands. Type pwndbg [filter] for a list.\r\nReading symbols from python...(no debugging symbols found)...done.\r\npwndbg> set exception-verbose on\r\nSet whether to print a full stacktracefor exceptions raised in Pwndbg commands to True\r\npwndbg> run -c \"print(1); print(2)\"\r\nStarting program: /usr/bin/python -c \"print(1); print(2)\"\r\n[Thread debugging using libthread_db enabled]\r\nUsing host libthread_db library \"/usr/lib/libthread_db.so.1\".\r\n1\r\n2\r\n[Inferior 1 (process 20590) exited normally]\r\npwndbg> entry -c \"print(1); print(2)\"\r\n('-c', 'print(1); print(2)')\r\nRunning '%s' run -c print(1); print(2)\r\n/bin/bash: -c: line 0: syntax error near unexpected token `('\r\n/bin/bash: -c: line 0: `exec /usr/bin/python -c print(1); print(2)'\r\nTraceback (most recent call last):\r\n  File \"/home/dc/installed/pwndbg/pwndbg/commands/__init__.py\", line 100, in __call__\r\n    return self.function(*args, **kwargs)\r\n  File \"/home/dc/installed/pwndbg/pwndbg/commands/__init__.py\", line 181, in _OnlyWithFile\r\n    return function(*a, **kw)\r\n  File \"/home/dc/installed/pwndbg/pwndbg/commands/start.py\", line 72, in entry\r\n    gdb.execute(run, from_tty=False)\r\ngdb.error: During startup program exited with code 1.\r\n\r\nIf that is an issue, you can report it on https://github.com/pwndbg/pwndbg/issues\r\n(Please don't forget to search if it hasn't been reported before)\r\nPS: Pull requests are welcome\r\n```\r\n\r\n### My version\r\n\r\n```\r\npwndbg> version\r\nGdb: GNU gdb (GDB) 8.0.1\r\nPython: 3.6.3 (default, Oct 24 2017, 14:48:20)  [GCC 7.2.0]\r\nPwndbg: 1.0.0 build: 5811010\r\n```\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nLaunches the target process after setting a breakpoint at a convenient\nentry point.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.elf\nimport pwndbg.events\nimport pwndbg.symbol\n\nbreak_on_first_instruction = False\n\n\n@pwndbg.events.start\ndef on_start():\n    global break_on_first_instruction\n    if break_on_first_instruction:\n        spec = \"*%#x\" % (int(pwndbg.elf.entry()))\n        gdb.Breakpoint(spec, temporary=True)\n        break_on_first_instruction = False\n\n\n@pwndbg.commands.Command\ndef start(*a):\n    \"\"\"\n    Set a breakpoint at a convenient location in the binary,\n    generally 'main', 'init', or the entry point.\n    \"\"\"\n    run = 'run ' + ' '.join(a)\n\n    symbols = [\"main\",\n                \"_main\",\n                \"start\",\n                \"_start\",\n                \"init\",\n                \"_init\"]\n\n    for symbol in symbols:\n        address = pwndbg.symbol.address(symbol)\n\n        if not address:\n            continue\n\n        b = gdb.Breakpoint(symbol, temporary=True)\n        gdb.execute(run, from_tty=False, to_string=True)\n        return\n\n    # Try a breakpoint at the binary entry\n    entry(*a)\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWithFile\ndef entry(*a):\n    \"\"\"\n    Set a breakpoint at the first instruction executed in\n    the target binary.\n    \"\"\"\n    global break_on_first_instruction\n    break_on_first_instruction = True\n    run = 'run ' + ' '.join(a)\n    gdb.execute(run, from_tty=False)\n", "path": "pwndbg/commands/start.py"}, {"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 gdb\n\nimport pwndbg.events\nimport pwndbg.memoize\n\nhint_msg = 'Loaded %i commands. Type pwndbg [filter] for a list.' % len(pwndbg.commands.Command.commands)\n\nprint(pwndbg.color.red(hint_msg))\ncur = (gdb.selected_inferior(), gdb.selected_thread())\n\n\ndef prompt_hook(*a):\n    global cur\n    new = (gdb.selected_inferior(), gdb.selected_thread())\n\n    if cur != new:\n        pwndbg.events.after_reload(start=False)\n        cur = new\n\n    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:\n        prompt_hook_on_stop(*a)\n\n\n@pwndbg.memoize.reset_on_stop\ndef prompt_hook_on_stop(*a):\n    pwndbg.commands.context.context()\n\n\ngdb.prompt_hook = prompt_hook\n", "path": "pwndbg/prompt.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nPrints structures in a manner similar to Windbg's \"dt\" command.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport glob\nimport os\nimport re\nimport subprocess\nimport tempfile\n\nimport gdb\n\nimport pwndbg.memory\nimport pwndbg.typeinfo\n\n\ndef get_type(v):\n    t = v.type\n    while not t.name:\n        if t.code == gdb.TYPE_CODE_PTR:\n            t = t.target()\n    return t.name\n\ndef get_typename(t):\n    return(str(t))\n\ndef get_arrsize(f):\n    t = f.type\n    if t.code != gdb.TYPE_CODE_ARRAY:\n        return 0\n    t2 = t.target()\n    s  = t2.sizeof\n    return int(t.sizeof / t2.sizeof)\n\ndef get_field_by_name(obj, field):\n    # Dereference once\n    if obj.type.code == gdb.TYPE_CODE_PTR:\n        obj = obj.dereference()\n    for f in re.split('(->|\\.|\\[\\d+\\])', field):\n        if not f: continue\n        if f   == '->':\n            obj = obj.dereference()\n        elif f == '.':\n            pass\n        elif f.startswith('['):\n            n   = int(f.strip('[]'))\n            obj = obj.cast(obj.dereference().type.pointer())\n            obj += n\n            obj = obj.dereference()\n        else:\n            obj = obj[f]\n    return obj\n\ndef happy(typename):\n    prefix = ''\n    if 'unsigned' in typename:\n        prefix = 'u'\n        typename = typename.replace('unsigned ', '')\n    return prefix + {\n    'char': 'char',\n    'short int': 'short',\n    'long int': 'long',\n    'int': 'int',\n    'long long': 'longlong',\n    'float': 'float',\n    'double': 'double'\n    }[typename]\n\ndef dt(name='', addr=None, obj = None):\n    \"\"\"\n    Dump out a structure type Windbg style.\n    \"\"\"\n    # Return value is a list of strings.of\n    # We concatenate at the end.\n    rv  = []\n\n    if obj and not name:\n        t = obj.type\n        while t.code == (gdb.TYPE_CODE_PTR):\n            t   = t.target()\n            obj = obj.dereference()\n        name = str(t)\n\n    # Lookup the type name specified by the user\n    else:\n        t = pwndbg.typeinfo.load(name)\n\n    # If it's not a struct (e.g. int or char*), bail\n    if t.code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_TYPEDEF, gdb.TYPE_CODE_UNION):\n        raise Exception(\"Not a structure: %s\" % t)\n\n    # If an address was specified, create a Value of the\n    # specified type at that address.\n    if addr is not None:\n        obj = pwndbg.memory.poi(t, addr)\n\n    # Header, optionally include the name\n    header = name\n    if obj: header = \"%s @ %s\" % (header, hex(int(obj.address)))\n    rv.append(header)\n\n    if t.strip_typedefs().code == gdb.TYPE_CODE_ARRAY:\n        return \"Arrays not supported yet\"\n    if t.strip_typedefs().code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):\n        t = {name: obj or gdb.Value(0).cast(t)}\n\n    for name, field in t.items():\n        # Offset into the parent structure\n        o     = getattr(field, 'bitpos', 0)/8\n        extra = str(field.type)\n        ftype = field.type.strip_typedefs()\n\n        if obj and obj.type.strip_typedefs().code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):\n            v  = obj[name]\n\n            if ftype.code == gdb.TYPE_CODE_INT:\n                v = hex(int(v))\n            if ftype.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY) \\\n                and ftype.target() == pwndbg.typeinfo.uchar:\n                data = pwndbg.memory.read(v.address, ftype.sizeof)\n                v = ' '.join('%02x' % b for b in data)\n\n            extra = v\n\n        # Adjust trailing lines in 'extra' to line up\n        # This is necessary when there are nested structures.\n        # Ideally we'd expand recursively if the type is complex.\n        extra_lines = []\n        for i, line in enumerate(str(extra).splitlines()):\n            if i == 0: extra_lines.append(line)\n            else:      extra_lines.append(35*' ' + line)\n        extra = '\\n'.join(extra_lines)\n\n        line  = \"    +0x%04x %-20s : %s\" % (o, name, extra)\n        rv.append(line)\n\n    return ('\\n'.join(rv))\n", "path": "pwndbg/dt.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nLaunches the target process after setting a breakpoint at a convenient\nentry point.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport shlex\n\nimport gdb\n\nimport pwndbg.commands\nimport pwndbg.elf\nimport pwndbg.events\nimport pwndbg.symbol\n\nbreak_on_first_instruction = False\n\n\n@pwndbg.events.start\ndef on_start():\n    global break_on_first_instruction\n    if break_on_first_instruction:\n        spec = \"*%#x\" % (int(pwndbg.elf.entry()))\n        gdb.Breakpoint(spec, temporary=True)\n        break_on_first_instruction = False\n\n\n@pwndbg.commands.Command\ndef start(*a):\n    \"\"\"\n    Set a breakpoint at a convenient location in the binary,\n    generally 'main', 'init', or the entry point.\n    \"\"\"\n    run = 'run ' + ' '.join(a)\n\n    symbols = [\"main\",\n                \"_main\",\n                \"start\",\n                \"_start\",\n                \"init\",\n                \"_init\"]\n\n    for symbol in symbols:\n        address = pwndbg.symbol.address(symbol)\n\n        if not address:\n            continue\n\n        b = gdb.Breakpoint(symbol, temporary=True)\n        gdb.execute(run, from_tty=False, to_string=True)\n        return\n\n    # Try a breakpoint at the binary entry\n    entry(*a)\n\n\n@pwndbg.commands.Command\n@pwndbg.commands.OnlyWithFile\ndef entry(*a):\n    \"\"\"\n    Set a breakpoint at the first instruction executed in\n    the target binary.\n    \"\"\"\n    global break_on_first_instruction\n    break_on_first_instruction = True\n    run = 'run ' + ' '.join(map(shlex.quote, a))\n    gdb.execute(run, from_tty=False)\n", "path": "pwndbg/commands/start.py"}, {"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 gdb\n\nimport pwndbg.events\nimport pwndbg.memoize\n\nhint_msg = 'Loaded %i commands. Type pwndbg [filter] for a list.' % len(pwndbg.commands.Command.commands)\n\nprint(pwndbg.color.red(hint_msg))\ncur = (gdb.selected_inferior(), gdb.selected_thread())\n\n\ndef prompt_hook(*a):\n    global cur\n    new = (gdb.selected_inferior(), gdb.selected_thread())\n\n    if cur != new:\n        pwndbg.events.after_reload(start=False)\n        cur = new\n\n    if pwndbg.proc.alive and pwndbg.proc.thread_is_stopped:\n        prompt_hook_on_stop(*a)\n\n\n@pwndbg.memoize.reset_on_stop\ndef prompt_hook_on_stop(*a):\n    pwndbg.commands.context.context()\n\n\n\ngdb.prompt_hook = prompt_hook\n", "path": "pwndbg/prompt.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\"\"\"\nPrints structures in a manner similar to Windbg's \"dt\" command.\n\"\"\"\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport glob\nimport os\nimport re\nimport subprocess\nimport tempfile\n\nimport gdb\n\nimport pwndbg.memory\nimport pwndbg.typeinfo\n\n\ndef get_type(v):\n    t = v.type\n    while not t.name:\n        if t.code == gdb.TYPE_CODE_PTR:\n            t = t.target()\n    return t.name\n\ndef get_typename(t):\n    return(str(t))\n\ndef get_arrsize(f):\n    t = f.type\n    if t.code != gdb.TYPE_CODE_ARRAY:\n        return 0\n    t2 = t.target()\n    s  = t2.sizeof\n    return int(t.sizeof / t2.sizeof)\n\ndef get_field_by_name(obj, field):\n    # Dereference once\n    if obj.type.code == gdb.TYPE_CODE_PTR:\n        obj = obj.dereference()\n    for f in re.split('(->|\\.|\\[\\d+\\])', field):\n        if not f: continue\n        if f   == '->':\n            obj = obj.dereference()\n        elif f == '.':\n            pass\n        elif f.startswith('['):\n            n   = int(f.strip('[]'))\n            obj = obj.cast(obj.dereference().type.pointer())\n            obj += n\n            obj = obj.dereference()\n        else:\n            obj = obj[f]\n    return obj\n\ndef happy(typename):\n    prefix = ''\n    if 'unsigned' in typename:\n        prefix = 'u'\n        typename = typename.replace('unsigned ', '')\n    return prefix + {\n    'char': 'char',\n    'short int': 'short',\n    'long int': 'long',\n    'int': 'int',\n    'long long': 'longlong',\n    'float': 'float',\n    'double': 'double'\n    }[typename]\n\ndef dt(name='', addr=None, obj = None):\n    \"\"\"\n    Dump out a structure type Windbg style.\n    \"\"\"\n    # Return value is a list of strings.of\n    # We concatenate at the end.\n    rv  = []\n\n    if obj and not name:\n        t = obj.type\n        while t.code == (gdb.TYPE_CODE_PTR):\n            t   = t.target()\n            obj = obj.dereference()\n        name = str(t)\n\n    # Lookup the type name specified by the user\n    else:\n        t = pwndbg.typeinfo.load(name)\n\n    # If it's not a struct (e.g. int or char*), bail\n    if t.code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_TYPEDEF, gdb.TYPE_CODE_UNION):\n        raise Exception(\"Not a structure: %s\" % t)\n\n    # If an address was specified, create a Value of the\n    # specified type at that address.\n    if addr is not None:\n        obj = pwndbg.memory.poi(t, addr)\n\n    # Header, optionally include the name\n    header = name\n    if obj: header = \"%s @ %s\" % (header, hex(int(obj.address)))\n    rv.append(header)\n\n    if t.strip_typedefs().code == gdb.TYPE_CODE_ARRAY:\n        return \"Arrays not supported yet\"\n    if t.strip_typedefs().code not in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):\n        t = {name: obj or gdb.Value(0).cast(t)}\n\n    for name, field in t.items():\n        # Offset into the parent structure\n        o     = getattr(field, 'bitpos', 0) // 8\n        b     = getattr(field, 'bitpos', 0) % 8\n        extra = str(field.type)\n        ftype = field.type.strip_typedefs()\n\n        if obj and obj.type.strip_typedefs().code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION):\n            v  = obj[name]\n\n            if ftype.code == gdb.TYPE_CODE_INT:\n                v = hex(int(v))\n            if ftype.code in (gdb.TYPE_CODE_PTR, gdb.TYPE_CODE_ARRAY) \\\n                and ftype.target() == pwndbg.typeinfo.uchar:\n                data = pwndbg.memory.read(v.address, ftype.sizeof)\n                v = ' '.join('%02x' % b for b in data)\n\n            extra = v\n\n        # Adjust trailing lines in 'extra' to line up\n        # This is necessary when there are nested structures.\n        # Ideally we'd expand recursively if the type is complex.\n        extra_lines = []\n        for i, line in enumerate(str(extra).splitlines()):\n            if i == 0: extra_lines.append(line)\n            else:      extra_lines.append(35*' ' + line)\n        extra = '\\n'.join(extra_lines)\n\n        bitpos = '' if not b else ('.%i' % b)\n\n        line  = \"    +0x%04x%s %-20s : %s\" % (o, bitpos, name, extra)\n        rv.append(line)\n\n    return ('\\n'.join(rv))\n", "path": "pwndbg/dt.py"}]}