internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pwndbg/pwndbg

Issue:
pwndbg will not display source code when source code has chinese characters
When use directory glibc source in gdb(directory /root/Pwn/glibc/glibc-2.23/malloc),  it will display the source code in pwndbg like this:
![image](https://user-images.githubusercontent.com/13138128/49008442-cb280f00-f1a8-11e8-9bd9-7bae523ecbfa.png)

However, **when I add Chinese characters in souce code like this**, pwndbg will not display it . Is this a bug? Will you fix it?
![image](https://user-images.githubusercontent.com/13138128/49008565-180be580-f1a9-11e8-8d09-3992ae6c6ceb.png)



Discussion:
Yes it is a bug. Can you show an example of those chars here on GitHub?

On Mon, Nov 26, 2018, 11:29 AM thinkycx <notifications@github.com wrote:

> When use directory glibc source in gdb(directory
> /root/Pwn/glibc/glibc-2.23/malloc), it will display the source code in
> pwndbg like this:
> [image: image]
> <https://user-images.githubusercontent.com/13138128/49008442-cb280f00-f1a8-11e8-9bd9-7bae523ecbfa.png>
>
> However, *when I add Chinese characters in souce code like this*, pwndbg
> will not display it . Is this a bug? Will you fix it?
> [image: image]
> <https://user-images.githubusercontent.com/13138128/49008565-180be580-f1a9-11e8-8d09-3992ae6c6ceb.png>
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pwndbg/pwndbg/issues/578>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AJi7Cv8tUuM8cIw4ZIwsvmDg4w-ffZtTks5uy8KFgaJpZM4YyvWa>
> .
>

OK. You can paste the Chinese code below in any code.
```
// comment 注释：中华人民共和国万岁！
```
@disconnect3d 

Resolving patch:
diff --git a/pwndbg/commands/context.py b/pwndbg/commands/context.py
--- a/pwndbg/commands/context.py
+++ b/pwndbg/commands/context.py
@@ -8,6 +8,7 @@
 import ast
 import codecs
 import sys
+from io import open
 
 import gdb
 
@@ -194,7 +195,7 @@ def context_disasm():
 @pwndbg.memoize.reset_on_start
 def get_highlight_source(filename):
     # Notice that the code is cached
-    with open(filename) as f:
+    with open(filename, encoding='utf-8') as f:
         source = f.read()
 
     if pwndbg.config.syntax_highlight:


Test patch:
Repository: pwndbg/pwndbg

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



Discussion:
@anthraxx can you check this out?
I can help here. When the program is not running we can start r2 with default parameters without any address. @disconnect3d I'll send a PR today if that's okay?

Resolving patch:
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 @@ def r2(arguments, no_seek=False):
 
     # 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:


Test patch:
Repository: pwndbg/pwndbg

Issue:
Don't activate the IDA view when stepping in the pwndbg
<!--
Before reporting a new issue, make sure that we do not have any duplicates already open.
If there is one it might be good to take part in the discussion there.

Please make sure you have checked that the issue persists on LATEST pwndbg version.

Below is a template for BUG REPORTS.
Don't include it if this is a FEATURE REQUEST.
-->


### Description

<!--
Briefly describe the problem you are having in a few paragraphs.
-->
By default the pwndbg will execute Jump(ea) function when we step to a new instruction. However the idc.Jump(ea) function calls the 
`inline bool jumpto(ea_t ea, int opnum=-1, int uijmp_flags=UIJMP_ACTIVATE)`
internally with the default parameter. You can see the UIJMP_ACTIVATE is the default flag and this will instruct the IDA to activate the target view, which will grab the focus (at least on Windows)
Because of this, every time I step in the pwndbg, the focus will shifted into IDA and I have to focus back to pwndbg manually which is quite annoying

### Steps to reproduce

<!--
What do we have to do to reproduce the problem?
If this is connected to particular C/asm code, 
please provide the smallest C code that reproduces the issue.
-->
Use the pwndbg with IDA Pro and then do stepping in pwndbg

### My setup

<!--
Show us your gdb/python/pwndbg/OS/IDA Pro version (depending on your case).

NOTE: We are currently supporting only Ubuntu installations.
It is known that pwndbg is not fully working e.g. on Arch Linux (the heap stuff is not working there).
If you would like to change this situation - help us improving pwndbg and supporting other distros!

This can be displayed in pwndbg through `version` command.

If it is somehow unavailable, use:
* `show version` - for gdb
* `py import sys; print(sys.version)` - for python
* pwndbg version/git commit id
-->
newest pwndbg with IDA Pro 7.2 on Windows

### Possible Fix
We can change the L230 of pwndbg/ida.py
from 
```return _ida.Jump(addr)```
to
```return _ida.jumpto(addr, -1, 0)```
which means we manually set the flag to 0, instead of UIJMP_ACTIVATE.


Discussion:
Yay, I literally had a love-hate relationship with pwndbg<->ida integration as sometimes I had this issue and sometimes I hadn't. I never had time to investigate it deeply why it happens so here we are!

Please, send a PR and thanks a lot for this!

Resolving patch:
diff --git a/pwndbg/ida.py b/pwndbg/ida.py
--- a/pwndbg/ida.py
+++ b/pwndbg/ida.py
@@ -227,7 +227,8 @@ def here():
 @withIDA
 @takes_address
 def Jump(addr):
-    return _ida.Jump(addr)
+    # uses C++ api instead of idc one to avoid activating the IDA window
+    return _ida.jumpto(addr, -1, 0)
 
 
 @withIDA


Test patch:
Repository: pwndbg/pwndbg

Issue:
Context displays wrong registers values for frames other than the newest one
There are two bugs regarding displaying of registers:
1. Wrong registers read
2. Improper caching

### Wrong registers read

We read registers from `newest_frame` instead of `selected_frame` - as a result, we display registers not from the current frame. This happens only for GDB>=7.9 as can be seen below.

To see this - break somewhere in a deep call, then do `up 2`, then display `context regs` and compare IP/PC with `info reg pc`.

Code responsible for the issue:
https://github.com/pwndbg/pwndbg/blob/a729a82fe44be9d0f9bb1ad1e732ee8c4fd6b7f5/pwndbg/regs.py#L246-L252

Some example:
![image](https://user-images.githubusercontent.com/10009354/57412836-74f8d680-71f2-11e9-9c4e-1414ab52aeac.png)

### Improper caching

I have fixed the 1st issue locally but apparently the context display wasn't right. When I did `pi pwndbg.memoize.memoize.caching = False` and  then `context regs` it has been fixed.

So I investigated this and found out that we have two (or more?) methods to fetch registers:
- `__getattr__`
- `__getitem__`

This can be seen here:
https://github.com/pwndbg/pwndbg/blob/a729a82fe44be9d0f9bb1ad1e732ee8c4fd6b7f5/pwndbg/regs.py#L269-L306

Not that far ago, we had some problems with caching and [we added the `@pwndbg.memoize.reset_on_prompt` cache invalidation for `__getattr__`](
https://github.com/pwndbg/pwndbg/commit/7815953781dd9744309b539532ad889bd125c93d).

It turns out, that some registers are fetched via `__getitem__` and cached and this bites us here: it seems the context register values are fetched, cached and not invalidated this way.

So to fix that, we need to add `@pwndbg.memoize.reset_on_prompt` to `__getitem__`.

**One could ask if we should have both methods at the first place - or - why do we have both of them?** I don't know. We should probably remove one of them and refactor other places to use just the other one. But this can be done in the future. If someone is willing to refactor this, please do so :).


Discussion:

Resolving patch:
diff --git a/pwndbg/regs.py b/pwndbg/regs.py
--- a/pwndbg/regs.py
+++ b/pwndbg/regs.py
@@ -249,7 +249,7 @@ def gdb77_get_register(name):
 
 @pwndbg.proc.OnlyWhenRunning
 def gdb79_get_register(name):
-    return gdb.newest_frame().read_register(name)
+    return gdb.selected_frame().read_register(name)
 
 try:
     gdb.Frame.read_register
@@ -285,6 +285,7 @@ def __getattr__(self, attr):
             return None
 
     @pwndbg.memoize.reset_on_stop
+    @pwndbg.memoize.reset_on_prompt
     def __getitem__(self, item):
         if isinstance(item, six.integer_types):
             return arch_to_regs[pwndbg.arch.current][item]


Test patch:
Repository: pwndbg/pwndbg

Issue:
xuntil doesn't work with PIE binaries before being run
`xuntil` was added in #604 and works except that it doesn't work with PIE binaries before being run.
This is because it expects an int argument. I'll look into using sloppy parsing.


Discussion:

Resolving patch:
diff --git a/pwndbg/commands/peda.py b/pwndbg/commands/peda.py
--- a/pwndbg/commands/peda.py
+++ b/pwndbg/commands/peda.py
@@ -30,18 +30,27 @@ def getpid():
 
 
 parser = argparse.ArgumentParser(description='Continue execution until an address or function.')
-parser.add_argument('target', help='Address or function to stop execution at')
-
+parser.add_argument('target', type=str, help='Address or function to stop execution at')
 
 @pwndbg.commands.ArgparsedCommand(parser)
 def xuntil(target):
-    addr = int(target)
-
-    if not pwndbg.memory.peek(addr):
-        print(message.error('Invalid address %#x' % addr))
-        return
+    try:
+        addr = int(target,0)
+        
+        if not pwndbg.memory.peek(addr):
+            print(message.error('Invalid address %#x' % addr))
+            return
+
+        spec = "*%#x" % (addr)
+    except (TypeError, ValueError):
+        #The following gdb command will throw an error if the symbol is not defined.
+        try:
+            result = gdb.execute('info address %s' % target, to_string=True, from_tty=False)
+        except gdb.error:
+            print(message.error("Unable to resolve %s" % target))
+            return    
+        spec = target
 
-    spec = "*%#x" % (addr)
     b = gdb.Breakpoint(spec, temporary=True)
     if pwndbg.proc.alive:
         gdb.execute("continue", from_tty=False)


Test patch:
Repository: pwndbg/pwndbg

Issue:
qemu local_path bug
### Description

It seems like some commands e.g. plt, got tries to use ELF file's content as path.

### Steps to reproduce

```
$ qemu-arm -g 23946 ./target
$ gdb-multiarch ./target
(gdb) target remote :23946
(gdb) plt # or
(gdb) got
```

### My setup

Ubuntu 18.04, branch c6473ba (master)

### Analysis (and temporary patch)

plt/got command uses `get_elf_info` at [elf.py](https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/elf.py#L95), which uses get_file at file.py.

It seems like the path itself should be used in [file.py L36](https://github.com/pwndbg/pwndbg/blob/c6473ba7aea797f7b4d2251febf419382564d3f8/pwndbg/file.py#L36):

https://github.com/pwndbg/pwndbg/blob/203f10710e8a9a195a7bade59661ed7f3e3e641c/pwndbg/file.py#L35-L36

to
```py
    if pwndbg.qemu.root() and recurse:
        return os.path.join(pwndbg.qemu.binfmt_root, path)
```

I'm not sure if it's ok in all cases, since I think relative path should be also searched, but it works on plt/got case since absolute path is used (e.g. if path is 'a/b', I'm not sure if binfmt_root + '/a/b' and 'a/b' shoud be searched.)


Discussion:
Hey, sorry for so long time with no reply. Can you send a PR with the proposed change so we could test this on different setups?

Resolving patch:
diff --git a/pwndbg/file.py b/pwndbg/file.py
--- a/pwndbg/file.py
+++ b/pwndbg/file.py
@@ -33,7 +33,7 @@ def get_file(path, recurse=1):
     local_path = path
 
     if pwndbg.qemu.root() and recurse:
-        return get(os.path.join(pwndbg.qemu.binfmt_root, path), 0)
+        return os.path.join(pwndbg.qemu.binfmt_root, path)
     elif pwndbg.remote.is_remote() and not pwndbg.qemu.is_qemu():
         local_path = tempfile.mktemp()
         error      = None


Test patch:
Repository: pwndbg/pwndbg

Issue:
`find_fake_fast` fails when providing a size argument
<!--
Before reporting a new issue, make sure that we do not have any duplicates already open.
If there is one it might be good to take part in the discussion there.

Please make sure you have checked that the issue persists on LATEST pwndbg version.

Below is a template for BUG REPORTS.
Don't include it if this is a FEATURE REQUEST.
-->


### Description

<!--
Briefly describe the problem you are having in a few paragraphs.
-->

Providing a size argument to the `find_fake_fast` command causes a TypeError at [heap.py:519](https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/commands/heap.py#L519).

### Steps to reproduce

<!--
What do we have to do to reproduce the problem?
If this is connected to particular C/asm code, 
please provide the smallest C code that reproduces the issue.
-->

1. Run gdb on a program that utilizes the heap
2. Once the heap is initialized, run `find_fake_fast &__malloc_hook 0x7f`

`find_fake_fast` working correctly as of commit 1158a3086d2eaa137e3ce30810539c1aa578e87a
![image](https://user-images.githubusercontent.com/25566997/81937222-583f6d80-95c1-11ea-9a79-ed2526dd15d8.png)

Same command, same program, updated to commit 609284cee279de345dcb0706e11a0b56abe349f4
![image](https://user-images.githubusercontent.com/25566997/81937802-1662f700-95c2-11ea-9fa6-b709c8eb24b3.png)


### My setup

<!--
Show us your gdb/python/pwndbg/OS/IDA Pro version (depending on your case).

NOTE: We are currently supporting only Ubuntu installations.
It is known that pwndbg is not fully working e.g. on Arch Linux (the heap stuff is not working there).
If you would like to change this situation - help us improving pwndbg and supporting other distros!

This can be displayed in pwndbg through `version` command.

If it is somehow unavailable, use:
* `show version` - for gdb
* `py import sys; print(sys.version)` - for python
* pwndbg version/git commit id
-->

Gdb:      7.11.1
Python:   3.5.2 (default, Oct  8 2019, 13:06:37)  [GCC 5.4.0 20160609]
Pwndbg:   1.1.0 build: 609284c
Capstone: 4.0.1024
Unicorn:  1.0.1



Discussion:

Resolving patch:
diff --git a/pwndbg/commands/heap.py b/pwndbg/commands/heap.py
--- a/pwndbg/commands/heap.py
+++ b/pwndbg/commands/heap.py
@@ -511,7 +511,7 @@ def find_fake_fast(addr, size=None):
     if size is None:
         sizes = range(min_fast, max_fast + 1, align)
     else:
-        sizes = [size]
+        sizes = [int(size)]
 
     print(C.banner("FAKE CHUNKS"))
     for size in sizes:


Test patch:
Repository: pwndbg/pwndbg

Issue:
QEMU uses binfmt root instead of pwndbg.qemu.root()
This bit here  should probably use pwndbg.qemu.root() instead of using the module variable directly: 

https://github.com/pwndbg/pwndbg/blob/609284cee279de345dcb0706e11a0b56abe349f4/pwndbg/file.py#L35


Discussion:

Resolving patch:
diff --git a/pwndbg/file.py b/pwndbg/file.py
--- a/pwndbg/file.py
+++ b/pwndbg/file.py
@@ -30,9 +30,9 @@ def get_file(path):
         The local path to the file
     """
     local_path = path
-
-    if pwndbg.qemu.root():
-        return os.path.join(pwndbg.qemu.binfmt_root, path)
+    qemu_root = pwndbg.qemu.root()
+    if qemu_root:
+        return os.path.join(qemu_root, path)
     elif pwndbg.remote.is_remote() and not pwndbg.qemu.is_qemu():
         local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir)
         error      = None


Test patch:
Repository: pwndbg/pwndbg

Issue:
Broken commands: lm, address, vprot
None of these commands seem to work.  They're intended to be pass-through to `vmmap` but they don't work as expected.

```
pwndbg> vmmap $pc
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
        0x10000000         0x10001000 rwxp     1000 1000   /tmp/pwntools/pwn-asm-Kevhi4/step3

pwndbg> vprot  $pc
Exception occured: vmmap: Value is not callable (not TYPE_CODE_FUNC). (<class 'RuntimeError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`

pwndbg> lm $pc
Exception occured: vmmap: Value is not callable (not TYPE_CODE_FUNC). (<class 'RuntimeError'>)
For more info invoke `set exception-verbose on` and rerun the command
or debug it by yourself with `set exception-debugger on`
```


Discussion:

Resolving patch:
diff --git a/pwndbg/commands/vmmap.py b/pwndbg/commands/vmmap.py
--- a/pwndbg/commands/vmmap.py
+++ b/pwndbg/commands/vmmap.py
@@ -52,7 +52,7 @@ def pages_filter(s):
                     help='Address or module name.')
 
 
-@pwndbg.commands.ArgparsedCommand(parser)
+@pwndbg.commands.ArgparsedCommand(parser, aliases=['lm', 'address', 'vprot'])
 @pwndbg.commands.OnlyWhenRunning
 def vmmap(pages_filter=None):
     pages = list(filter(pages_filter, pwndbg.vmmap.get()))
diff --git a/pwndbg/commands/windbg.py b/pwndbg/commands/windbg.py
--- a/pwndbg/commands/windbg.py
+++ b/pwndbg/commands/windbg.py
@@ -361,31 +361,10 @@ def ln(value=None):
     if x:
         result = '(%#x)   %s' % (value, x)
         print(result)
-
-@pwndbg.commands.QuietSloppyParsedCommand
-@pwndbg.commands.OnlyWhenRunning
-def lm(map):
-    """
-    Windbg compatibility alias for 'vmmap' command.
-    """
-    return pwndbg.commands.vmmap.vmmap(map)
-
-@pwndbg.commands.QuietSloppyParsedCommand
-@pwndbg.commands.OnlyWhenRunning
-def address(map):
-    """
-    Windbg compatibility alias for 'vmmap' command.
-    """
-    return pwndbg.commands.vmmap.vmmap(map)
-
-
-@pwndbg.commands.QuietSloppyParsedCommand
-@pwndbg.commands.OnlyWhenRunning
-def vprot(map):
-    """
-    Windbg compatibility alias for 'vmmap' command.
-    """
-    return pwndbg.commands.vmmap.vmmap(map)
+# The three commands are aliases for `vmmap` and are set so in vmmap.py
+# lm
+# address
+# vprot
 
 @pwndbg.commands.ArgparsedCommand("Not be windows.")
 @pwndbg.commands.OnlyWhenRunning


Test patch:
Repository: pwndbg/pwndbg

Issue:
pwndbg gets stuck in GDB 10.1
<!--
Before reporting a new issue, make sure that we do not have any duplicates already open.
If there is one it might be good to take part in the discussion there.

Please make sure you have checked that the issue persists on LATEST pwndbg version.

Below is a template for BUG REPORTS.
Don't include it if this is a FEATURE REQUEST.
-->


### Description
pwndbg gets stuck in GDB 10.1
<!--
Briefly describe the problem you are having in a few paragraphs.
-->

### Steps to reproduce
![Screenshot_20201227_212816](https://user-images.githubusercontent.com/16643669/103172053-aa50ad00-488b-11eb-9326-b8a5745d88aa.png)

<!--
What do we have to do to reproduce the problem?
If this is connected to particular C/asm code, 
please provide the smallest C code that reproduces the issue.
-->

### My setup

<!--
Show us your gdb/python/pwndbg/OS/IDA Pro version (depending on your case).

NOTE: We are currently supporting only Ubuntu installations.
It is known that pwndbg is not fully working e.g. on Arch Linux (the heap stuff is not working there).
If you would like to change this situation - help us improving pwndbg and supporting other distros!

This can be displayed in pwndbg through `version` command.

If it is somehow unavailable, use:
* `show version` - for gdb
* `py import sys; print(sys.version)` - for python
* pwndbg version/git commit id
-->
```
Gdb:      10.1
Python:   3.8.6 (default, Sep 30 2020, 04:00:38)  [GCC 10.2.0]
Pwndbg:   1.1.0
Capstone: 4.0.1024
Unicorn:  1.0.2
```


Discussion:

Resolving patch:
diff --git a/pwndbg/heap/__init__.py b/pwndbg/heap/__init__.py
--- a/pwndbg/heap/__init__.py
+++ b/pwndbg/heap/__init__.py
@@ -8,18 +8,8 @@
 
 heap_chain_limit = pwndbg.config.Parameter('heap-dereference-limit', 8, 'number of bins to dereference')
 
-@pwndbg.events.new_objfile
+@pwndbg.events.start
 def update():
-    import pwndbg.heap.dlmalloc
     import pwndbg.heap.ptmalloc
-
     global current
-
-
-    if pwndbg.symbol.address('ptmalloc_init'):
-        current = pwndbg.heap.ptmalloc.Heap()
-
-    else:
-        # Default to ptmalloc heap for now until
-        # there are more implementations
-        current = pwndbg.heap.ptmalloc.Heap()
+    current = pwndbg.heap.ptmalloc.Heap()
diff --git a/pwndbg/heap/dlmalloc.py b/pwndbg/heap/dlmalloc.py
deleted file mode 100644
--- a/pwndbg/heap/dlmalloc.py
+++ /dev/null
@@ -1,11 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import gdb
-
-import pwndbg.events
-import pwndbg.typeinfo
-
-
-class Heap(pwndbg.heap.heap.BaseHeap):
-    pass


Test patch: