Repository: pwndbg/pwndbg

Issue:
`start` raises exception `context:  (<class 'StopIteration'>)`
### Description

Using the `start` command to open an executable results in an exception : **context:  (<class 'StopIteration'>)**. 

### Steps to reproduce

1. `gdb name_of_the_binary`
2. `pwndbg> start`

### My setup

Gdb:      10.1
Python:   3.9.1rc1 (default, Nov 27 2020, 19:38:39)  [GCC 10.2.0]
Pwndbg:   1.1.0 build: bf49bf8
Capstone: 4.0.1024
Unicorn:  1.0.2

-->



Discussion:
Can you try again, but set:

```
set exception-verbose on
set python print-stack full
```

And include the output of the full stack trace?

i got the same problem in context.py
```
pwndbg> set exception-verbose on
Set whether to print a full stacktrace for exceptions raised in Pwndbg commands to True
pwndbg> context
Traceback (most recent call last):
  File "/home/x3ero0/pwndbg/pwndbg/commands/__init__.py", line 130, in __call__
    return self.function(*args, **kwargs)
  File "/home/x3ero0/pwndbg/pwndbg/commands/__init__.py", line 221, in _OnlyWhenRunning
    return function(*a, **kw)
  File "/home/x3ero0/pwndbg/pwndbg/commands/context.py", line 334, in context
    result[target].extend(func(target=out,
  File "/home/x3ero0/pwndbg/pwndbg/commands/context.py", line 479, in context_disasm
    cs = next(iter(pwndbg.disasm.get_disassembler_cached.cache.values()))
StopIteration

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)
To generate the report and open a browser, you may run `bugreport --run-browser`
PS: Pull requests are welcome
pwndbg> set python print-stack full
pwndbg> context
Traceback (most recent call last):
  File "/home/x3ero0/pwndbg/pwndbg/commands/__init__.py", line 130, in __call__
    return self.function(*args, **kwargs)
  File "/home/x3ero0/pwndbg/pwndbg/commands/__init__.py", line 221, in _OnlyWhenRunning
    return function(*a, **kw)
  File "/home/x3ero0/pwndbg/pwndbg/commands/context.py", line 334, in context
    result[target].extend(func(target=out,
  File "/home/x3ero0/pwndbg/pwndbg/commands/context.py", line 479, in context_disasm
    cs = next(iter(pwndbg.disasm.get_disassembler_cached.cache.values()))
StopIteration
```
it happened when pwndbg tried displaying context when eip=0x61616164.

```
pwndbg> info reg
eax            0x240               576
ecx            0xffffffff          -1
edx            0x240               576
ebx            0x61616162          1633771874
esp            0xffa1d3b0          0xffa1d3b0
ebp            0x61616163          0x61616163
esi            0xf7f04000          -135249920
edi            0xf7f04000          -135249920
eip            0x61616164          0x61616164
eflags         0x10282             [ SF IF RF ]
cs             0x23                35
ss             0x2b                43
ds             0x2b                43
es             0x2b                43
fs             0x0                 0
gs             0x63                99

pwndbg> stack 10
00:0000│ esp  0xffa1d3b0 ◂— 0x61616165 ('eaaa')
01:0004│      0xffa1d3b4 ◂— 0x61616166 ('faaa')
02:0008│      0xffa1d3b8 ◂— 0x61616167 ('gaaa')
03:000c│      0xffa1d3bc ◂— 0x61616168 ('haaa')
04:0010│      0xffa1d3c0 ◂— 0x61616169 ('iaaa')
05:0014│      0xffa1d3c4 ◂— 0x6161616a ('jaaa')
06:0018│      0xffa1d3c8 ◂— 0x6161616b ('kaaa')
07:001c│      0xffa1d3cc ◂— 0x6161616c ('laaa')
08:0020│      0xffa1d3d0 ◂— 0x6161616d ('maaa')
09:0024│      0xffa1d3d4 ◂— 0x6161616e ('naaa')
```


Resolving patch:
diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py
--- a/pwndbg/commands/context.py
+++ b/pwndbg/commands/context.py
@@ -476,9 +476,10 @@ def context_disasm(target=sys.stdout, with_banner=True, width=None):
     syntax = pwndbg.disasm.CapstoneSyntax[flavor]
 
     # Get the Capstone object to set disassembly syntax
-    cs = next(iter(pwndbg.disasm.get_disassembler_cached.cache.values()))
+    cs = next(iter(pwndbg.disasm.get_disassembler_cached.cache.values()), None)
 
-    if cs.syntax != syntax:
+    # The `None` case happens when the cache was not filled yet (see e.g. #881)
+    if cs is not None and cs.syntax != syntax:
         pwndbg.memoize.reset()
 
     banner = [pwndbg.ui.banner("disasm", target=target, width=width)]


Test patch: