Repository: pwndbg/pwndbg

Issue:
no type named uint16 in rust
### Description

So, I think I correctly installed pwndbg on my system, when I run simple rust code like this: 

```rust
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
}
```

And I try to debug it using gdb with pwndbg I got this problem: 
```
Traceback (most recent call last):
  File "/usr/share/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```

### My setup

gdb
```
Name            : gdb
Version         : 10.1-2
Description     : The GNU Debugger
Architecture    : x86_64
URL             : https://www.gnu.org/software/gdb/
Licenses        : GPL3
Groups          : None
Provides        : None
Depends On      : glibc  ncurses  libncursesw.so=6-64  gcc-libs  expat  xz  mpfr  source-highlight  gdb-common=10.1  readline  libreadline.so=8-64  guile  python  libelf
Optional Deps   : None
Required By     : peda  pwndbg-git
Optional For    : rustup
Conflicts With  : None
Replaces        : None
Installed Size  : 9.72 MiB
Packager        : Anatol Pomozov <anatol.pomozov@gmail.com>
Build Date      : Wed 04 Nov 2020 08:44:41 PM CET
Install Date    : Sat 14 Nov 2020 11:15:29 PM CET
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature
```
python
```
Name            : python
Version         : 3.8.6-1
Description     : Next generation of the python high-level scripting language
Architecture    : x86_64
URL             : https://www.python.org/
Licenses        : custom
Groups          : None
Provides        : python3
Depends On      : bzip2  expat  gdbm  libffi  libnsl  libxcrypt  openssl  zlib
Optional Deps   : python-setuptools [installed]
                  python-pip [installed]
                  sqlite [installed]
                  mpdecimal: for decimal
                  xz: for lzma [installed]
                  tk: for tkinter [installed]
Required By     : ...
Optional For    : ...
Conflicts With  : None
Replaces        : python3
Installed Size  : 77.85 MiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Wed 30 Sep 2020 06:00:38 AM CEST
Install Date    : Fri 09 Oct 2020 09:13:49 PM CEST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature
```

pwndbg
```
Name            : pwndbg-git
Version         : 2020.07.23.879.29f962c-1
Description     : Makes debugging with GDB suck less
Architecture    : any
URL             : https://github.com/pwndbg/pwndbg
Licenses        : MIT
Groups          : None
Provides        : pwndbg
Depends On      : gdb  python-capstone  python-unicorn  python-pycparser  python-psutil  python-ptrace  python-pyelftools  python-six  python-future  python-pygments
Optional Deps   : checksec: checksec command support
                  ropper: ropper command support
                  ropgadget: ropgadget command support
                  radare2: radare2 command support
Required By     : None
Optional For    : None
Conflicts With  : pwndbg
Replaces        : None
Installed Size  : 3.89 MiB
Packager        : Unknown Packager
Build Date      : Sat 14 Nov 2020 11:51:32 PM CET
Install Date    : Mon 16 Nov 2020 11:00:32 PM CET
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : None
```

rustup 1.22.1 (2020-07-08)
rustc 1.47.0 (18bf6b4f0 2020-10-07)

#### Small remark
I installed pwndbg using `pacman` at first, but it was not able to get correct the correct python version, so I had to install all dependencies in pip myself (I used a bits of information from `setup.sh`).
no type named uint16 in rust
### Description

So, I think I correctly installed pwndbg on my system, when I run simple rust code like this: 

```rust
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
}
```

And I try to debug it using gdb with pwndbg I got this problem: 
```
Traceback (most recent call last):
  File "/usr/share/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/usr/share/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```

### My setup

gdb
```
Name            : gdb
Version         : 10.1-2
Description     : The GNU Debugger
Architecture    : x86_64
URL             : https://www.gnu.org/software/gdb/
Licenses        : GPL3
Groups          : None
Provides        : None
Depends On      : glibc  ncurses  libncursesw.so=6-64  gcc-libs  expat  xz  mpfr  source-highlight  gdb-common=10.1  readline  libreadline.so=8-64  guile  python  libelf
Optional Deps   : None
Required By     : peda  pwndbg-git
Optional For    : rustup
Conflicts With  : None
Replaces        : None
Installed Size  : 9.72 MiB
Packager        : Anatol Pomozov <anatol.pomozov@gmail.com>
Build Date      : Wed 04 Nov 2020 08:44:41 PM CET
Install Date    : Sat 14 Nov 2020 11:15:29 PM CET
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature
```
python
```
Name            : python
Version         : 3.8.6-1
Description     : Next generation of the python high-level scripting language
Architecture    : x86_64
URL             : https://www.python.org/
Licenses        : custom
Groups          : None
Provides        : python3
Depends On      : bzip2  expat  gdbm  libffi  libnsl  libxcrypt  openssl  zlib
Optional Deps   : python-setuptools [installed]
                  python-pip [installed]
                  sqlite [installed]
                  mpdecimal: for decimal
                  xz: for lzma [installed]
                  tk: for tkinter [installed]
Required By     : ...
Optional For    : ...
Conflicts With  : None
Replaces        : python3
Installed Size  : 77.85 MiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Wed 30 Sep 2020 06:00:38 AM CEST
Install Date    : Fri 09 Oct 2020 09:13:49 PM CEST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature
```

pwndbg
```
Name            : pwndbg-git
Version         : 2020.07.23.879.29f962c-1
Description     : Makes debugging with GDB suck less
Architecture    : any
URL             : https://github.com/pwndbg/pwndbg
Licenses        : MIT
Groups          : None
Provides        : pwndbg
Depends On      : gdb  python-capstone  python-unicorn  python-pycparser  python-psutil  python-ptrace  python-pyelftools  python-six  python-future  python-pygments
Optional Deps   : checksec: checksec command support
                  ropper: ropper command support
                  ropgadget: ropgadget command support
                  radare2: radare2 command support
Required By     : None
Optional For    : None
Conflicts With  : pwndbg
Replaces        : None
Installed Size  : 3.89 MiB
Packager        : Unknown Packager
Build Date      : Sat 14 Nov 2020 11:51:32 PM CET
Install Date    : Mon 16 Nov 2020 11:00:32 PM CET
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : None
```

rustup 1.22.1 (2020-07-08)
rustc 1.47.0 (18bf6b4f0 2020-10-07)

#### Small remark
I installed pwndbg using `pacman` at first, but it was not able to get correct the correct python version, so I had to install all dependencies in pip myself (I used a bits of information from `setup.sh`).


Discussion:
What is the correct name for a unsigned 2-byte integer in Rust?  We should add it to the `lookup_types` code.
From what I see in [`lookup_types`](https://github.com/pwndbg/pwndbg/blob/301012abf213770c74f871417db7b5f33b4f5fca/pwndbg/typeinfo.py#L51), Rusts [`u16`](https://doc.rust-lang.org/std/primitive.u16.html) type seems to be there already, hmm.
Can it be that this specific binary did not have debug info for that type? What if you used u16 explicitly in Rust code?
> Can it be that this specific binary did not have debug info for that type? What if you used u16 explicitly in Rust code?

Not really, I just started with Rust, and I was trying to run this code:
```rust
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
}
```
I'm also having this behavior when trying to debug this simple Rust example:

```rust
fn main() {
    let a = 2;
    let result = stack_only(a);
    dbg!(result);
}

fn stack_only(b: i32) -> i32 {
    let c = 3;
    return b + c + stack_and_heap();
}

fn stack_and_heap() -> i32 {
    let d = 5;
    let e = Box::new(7);
    return d + *e;
}
```

**Error:** 

```
Traceback (most recent call last):
  File "/home/x/.pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```

**Current setup:**

➜  ~ gdb --version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
➜  ~ python3 --version
Python 3.8.5
➜  ~ rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0 (7eac88abb 2020-11-16)`
➜  ~ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)
I'm on the same page now. I searched about this error and I figured out I probably need to install rust-gdb (not yet tried). 

Mac OS High Sierra (10.13.6) 

$ gdb --version
GNU gdb (GDB) 10.1

$ python3 --version 
Python 3.6.2

$ rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)

$ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)

Error: 
```
Traceback (most recent call last):
  File "/Users/junhong/temp/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```
Does Rust have a u16 or another similar type that would take the place of
uint16?

*Zach Riggle*


On Sun, Dec 20, 2020 at 5:46 PM Junhong Kim <notifications@github.com>
wrote:

> I'm on the same page now. I searched about this error and I figured out I
> probably need to install rust-gdb (not yet tried).
>
> Mac OS High Sierra (10.13.6)
>
> $ gdb --version
> GNU gdb (GDB) 10.1
>
> $ python3 --version
> Python 3.6.2
>
> $ rustup --version
> rustup 1.23.1 (3df2264a9 2020-11-30)
>
> $ rustc --version
> rustc 1.48.0 (7eac88abb 2020-11-16)
>
> Error:
>
> Traceback (most recent call last):
>   File "/Users/junhong/temp/pwndbg/pwndbg/events.py", line 165, in caller
>     func()
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 51, in update
>     module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
>     raise exc
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
>     return gdb.lookup_type(type_str)
> gdb.error: No type named uint16.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pwndbg/pwndbg/issues/855#issuecomment-748689380>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAA3IGEOD5X3R4Q262QAT7TSV2EGDANCNFSM4TXZTNNA>
> .
>

yeah, it's `u16` (https://doc.rust-lang.org/book/ch03-02-data-types.html)
Yup, but we have `u16` in the types list, added just for the sake of supporting Rust I believe: https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/typeinfo.py#L51 but somehow, it is not detected it.

That's why I asked that maybe some debug symbols are missing. I will look into this on my side.
I can confirm that missing debugging symbols is indeed the issue. This can be seen by building a rust binary with the following command: `rustc -g ./main.rs` and then debugging it with:
```
gdb ./main
break main::main
run
pi pwndbg.typeinfo.lookup_types('u16')
```
The last command succeeds returning a gdb.Type instance (e.g.`<gdb.Type object at 0x7f12b7513698>`), which is not the case if we don't use `-g`.

We can then confirm that the debug info indeed has information about the `u16` type within the binary:
```
$ objdump --debugging main | grep 'DW_AT_name.*: u16$' -A 3
    <12f7>   DW_AT_name        : (indirect string, offset: 0xfc2): u16
    <12fb>   DW_AT_encoding    : 7	(unsigned)
    <12fc>   DW_AT_byte_size   : 2
 <1><12fd>: Abbrev Number: 17 (DW_TAG_pointer_type)
--
    <359e>   DW_AT_name        : (indirect string, offset: 0xfc2): u16
    <35a2>   DW_AT_encoding    : 7	(unsigned)
    <35a3>   DW_AT_byte_size   : 2
 <1><35a4>: Abbrev Number: 2 (DW_TAG_namespace)
```

Which unfortunately, isn't the case if we compile the binary WITHOUT debugging symbols:
```
$ rustc main.rs && objdump --debugging main | grep 'DW_AT_name.*: u16$' -A 3
warning: unused `std::result::Result` that must be used
 --> main.rs:6:5
  |
6 |     io::stdin().read_line(&mut input);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
  = note: this `Result` may be an `Err` variant, which should be handled

warning: 1 warning emitted

$
```

Hi, just wondering if this issue has been resolved yet or if there is a workaround for it? 
any solution available now?
Most likely you can have a workaround by adding a file/symbol file with such symbols.
using rust-gdb instead of gdb solved the issue for me
@laurentHYZ Using `rust-gdb` doesn't really solve the issue for me. Are you sure it did for you?

One solution could be `set language c`, then getting all types from C, then `set language <old>` (e.g. 'auto' or 'rust').

However, we can't do it in `typeinfo.py` in its `update`: doing pure `gdb.execute('set language c'); gdb.lookup_type('char'); gdb.execute('set language <old>')` doesn't work because the C types are available only upon a next GDB event is fired off.
> @laurentHYZ Using `rust-gdb` doesn't really solve the issue for me. Are you sure it did for you?
> 
> One solution could be `set language c`, then getting all types from C, then `set language <old>` (e.g. 'auto' or 'rust').
> 
> However, we can't do it in `typeinfo.py` in its `update`: doing pure `gdb.execute('set language c'); gdb.lookup_type('char'); gdb.execute('set language <old>')` doesn't work because the C types are available only upon a next GDB event is fired off.

I can also confirm that rust-gdb does not work for me either. Has any else figured out a work around?

have you found a solution for the problem above?
Thanks to all.
> have you found a solution for the problem above? Thanks to all.

After posting my comment, I relalized the workaround everyone has been talking about.

### If you make a simple rust project
`cargo new gdbtest`

#### build it
`cd gdbtest && cargo build`

#### open the debug executable with gdb
`gdb target/debug/gdbtest`

#### At your pwndbg prompt you must must manually enter the following
`pwndbg> set language c`

#### Then you can set your break point and run it, and it will work fine
`pwndbg> b main.rs:1`
`pwndbg> r`

#### Here is a screen shot for verification
![rustgdbexample](https://user-images.githubusercontent.com/35334658/138532674-01906ddc-d0c6-47a5-a7b7-44b80f1d0ad0.png)



Yes this true..putting "set language c" after launch gdb <bin> it work correctly. Do you know if there is a way to arrange in a good way the screen information?
> pwndbg> set language c

Worked for me. @mattcoding4days Cheers mate!
@disconnect3d is the plan here still to add a call to `set language c` in `pwndbg` when a Rust binary is detected? I think we should probably close this issue and make a dedicated issue for that change.
Interestingly, GDB does seem to do this by itself -- by changing the language from Rust to C -- and our error fixes itself, but we still display the exception since it occurred...

Though it may be me missing the debug_gdb_scripts or sth and so Rust lang is disabled because of it?

Some of this can be seen here:
```
$ gdb --quiet --nx ./target/debug/tester
Reading symbols from ./target/debug/tester...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/dc/dbgtest/tester/target/debug/tester.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) show language
The current source language is "auto; currently rust".
(gdb) pi gdb.lookup_type('long')
Python Exception <class 'gdb.error'> No type named long.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('i16')
Python Exception <class 'gdb.error'> No type named i16.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('int16_t')
Python Exception <class 'gdb.error'> No type named int16_t.:
Error while executing Python code.
(gdb) break main
Breakpoint 1 at 0x51b0
(gdb) run
Starting program: /home/dc/dbgtest/tester/target/debug/tester
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x00005555555591b0 in main ()
(gdb) show language
The current source language is "auto; currently c".
(gdb) pi gdb.lookup_type('int16_t')
<gdb.Type object at 0x7ff0f0287a80>
(gdb) pi gdb.lookup_type('i16')
Python Exception <class 'gdb.error'> No type named i16.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('long')
<gdb.Type object at 0x7ff0f0287b98>
(gdb)
```
What is the correct name for a unsigned 2-byte integer in Rust?  We should add it to the `lookup_types` code.
From what I see in [`lookup_types`](https://github.com/pwndbg/pwndbg/blob/301012abf213770c74f871417db7b5f33b4f5fca/pwndbg/typeinfo.py#L51), Rusts [`u16`](https://doc.rust-lang.org/std/primitive.u16.html) type seems to be there already, hmm.
Can it be that this specific binary did not have debug info for that type? What if you used u16 explicitly in Rust code?
> Can it be that this specific binary did not have debug info for that type? What if you used u16 explicitly in Rust code?

Not really, I just started with Rust, and I was trying to run this code:
```rust
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
}
```
I'm also having this behavior when trying to debug this simple Rust example:

```rust
fn main() {
    let a = 2;
    let result = stack_only(a);
    dbg!(result);
}

fn stack_only(b: i32) -> i32 {
    let c = 3;
    return b + c + stack_and_heap();
}

fn stack_and_heap() -> i32 {
    let d = 5;
    let e = Box::new(7);
    return d + *e;
}
```

**Error:** 

```
Traceback (most recent call last):
  File "/home/x/.pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/home/x/.pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```

**Current setup:**

➜  ~ gdb --version
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
➜  ~ python3 --version
Python 3.8.5
➜  ~ rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.48.0 (7eac88abb 2020-11-16)`
➜  ~ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)
I'm on the same page now. I searched about this error and I figured out I probably need to install rust-gdb (not yet tried). 

Mac OS High Sierra (10.13.6) 

$ gdb --version
GNU gdb (GDB) 10.1

$ python3 --version 
Python 3.6.2

$ rustup --version
rustup 1.23.1 (3df2264a9 2020-11-30)

$ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)

Error: 
```
Traceback (most recent call last):
  File "/Users/junhong/temp/pwndbg/pwndbg/events.py", line 165, in caller
    func()
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 51, in update
    module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
    raise exc
  File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
    return gdb.lookup_type(type_str)
gdb.error: No type named uint16.
```
Does Rust have a u16 or another similar type that would take the place of
uint16?

*Zach Riggle*


On Sun, Dec 20, 2020 at 5:46 PM Junhong Kim <notifications@github.com>
wrote:

> I'm on the same page now. I searched about this error and I figured out I
> probably need to install rust-gdb (not yet tried).
>
> Mac OS High Sierra (10.13.6)
>
> $ gdb --version
> GNU gdb (GDB) 10.1
>
> $ python3 --version
> Python 3.6.2
>
> $ rustup --version
> rustup 1.23.1 (3df2264a9 2020-11-30)
>
> $ rustc --version
> rustc 1.48.0 (7eac88abb 2020-11-16)
>
> Error:
>
> Traceback (most recent call last):
>   File "/Users/junhong/temp/pwndbg/pwndbg/events.py", line 165, in caller
>     func()
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 51, in update
>     module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16')
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 39, in lookup_types
>     raise exc
>   File "/Users/junhong/temp/pwndbg/pwndbg/typeinfo.py", line 36, in lookup_types
>     return gdb.lookup_type(type_str)
> gdb.error: No type named uint16.
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/pwndbg/pwndbg/issues/855#issuecomment-748689380>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAA3IGEOD5X3R4Q262QAT7TSV2EGDANCNFSM4TXZTNNA>
> .
>

yeah, it's `u16` (https://doc.rust-lang.org/book/ch03-02-data-types.html)
Yup, but we have `u16` in the types list, added just for the sake of supporting Rust I believe: https://github.com/pwndbg/pwndbg/blob/dev/pwndbg/typeinfo.py#L51 but somehow, it is not detected it.

That's why I asked that maybe some debug symbols are missing. I will look into this on my side.
I can confirm that missing debugging symbols is indeed the issue. This can be seen by building a rust binary with the following command: `rustc -g ./main.rs` and then debugging it with:
```
gdb ./main
break main::main
run
pi pwndbg.typeinfo.lookup_types('u16')
```
The last command succeeds returning a gdb.Type instance (e.g.`<gdb.Type object at 0x7f12b7513698>`), which is not the case if we don't use `-g`.

We can then confirm that the debug info indeed has information about the `u16` type within the binary:
```
$ objdump --debugging main | grep 'DW_AT_name.*: u16$' -A 3
    <12f7>   DW_AT_name        : (indirect string, offset: 0xfc2): u16
    <12fb>   DW_AT_encoding    : 7	(unsigned)
    <12fc>   DW_AT_byte_size   : 2
 <1><12fd>: Abbrev Number: 17 (DW_TAG_pointer_type)
--
    <359e>   DW_AT_name        : (indirect string, offset: 0xfc2): u16
    <35a2>   DW_AT_encoding    : 7	(unsigned)
    <35a3>   DW_AT_byte_size   : 2
 <1><35a4>: Abbrev Number: 2 (DW_TAG_namespace)
```

Which unfortunately, isn't the case if we compile the binary WITHOUT debugging symbols:
```
$ rustc main.rs && objdump --debugging main | grep 'DW_AT_name.*: u16$' -A 3
warning: unused `std::result::Result` that must be used
 --> main.rs:6:5
  |
6 |     io::stdin().read_line(&mut input);
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_must_use)]` on by default
  = note: this `Result` may be an `Err` variant, which should be handled

warning: 1 warning emitted

$
```

Hi, just wondering if this issue has been resolved yet or if there is a workaround for it? 
any solution available now?
Most likely you can have a workaround by adding a file/symbol file with such symbols.
using rust-gdb instead of gdb solved the issue for me
@laurentHYZ Using `rust-gdb` doesn't really solve the issue for me. Are you sure it did for you?

One solution could be `set language c`, then getting all types from C, then `set language <old>` (e.g. 'auto' or 'rust').

However, we can't do it in `typeinfo.py` in its `update`: doing pure `gdb.execute('set language c'); gdb.lookup_type('char'); gdb.execute('set language <old>')` doesn't work because the C types are available only upon a next GDB event is fired off.
> @laurentHYZ Using `rust-gdb` doesn't really solve the issue for me. Are you sure it did for you?
> 
> One solution could be `set language c`, then getting all types from C, then `set language <old>` (e.g. 'auto' or 'rust').
> 
> However, we can't do it in `typeinfo.py` in its `update`: doing pure `gdb.execute('set language c'); gdb.lookup_type('char'); gdb.execute('set language <old>')` doesn't work because the C types are available only upon a next GDB event is fired off.

I can also confirm that rust-gdb does not work for me either. Has any else figured out a work around?

have you found a solution for the problem above?
Thanks to all.
> have you found a solution for the problem above? Thanks to all.

After posting my comment, I relalized the workaround everyone has been talking about.

### If you make a simple rust project
`cargo new gdbtest`

#### build it
`cd gdbtest && cargo build`

#### open the debug executable with gdb
`gdb target/debug/gdbtest`

#### At your pwndbg prompt you must must manually enter the following
`pwndbg> set language c`

#### Then you can set your break point and run it, and it will work fine
`pwndbg> b main.rs:1`
`pwndbg> r`

#### Here is a screen shot for verification
![rustgdbexample](https://user-images.githubusercontent.com/35334658/138532674-01906ddc-d0c6-47a5-a7b7-44b80f1d0ad0.png)



Yes this true..putting "set language c" after launch gdb <bin> it work correctly. Do you know if there is a way to arrange in a good way the screen information?
> pwndbg> set language c

Worked for me. @mattcoding4days Cheers mate!
@disconnect3d is the plan here still to add a call to `set language c` in `pwndbg` when a Rust binary is detected? I think we should probably close this issue and make a dedicated issue for that change.
Interestingly, GDB does seem to do this by itself -- by changing the language from Rust to C -- and our error fixes itself, but we still display the exception since it occurred...

Though it may be me missing the debug_gdb_scripts or sth and so Rust lang is disabled because of it?

Some of this can be seen here:
```
$ gdb --quiet --nx ./target/debug/tester
Reading symbols from ./target/debug/tester...
warning: Missing auto-load script at offset 0 in section .debug_gdb_scripts
of file /home/dc/dbgtest/tester/target/debug/tester.
Use `info auto-load python-scripts [REGEXP]' to list them.
(gdb) show language
The current source language is "auto; currently rust".
(gdb) pi gdb.lookup_type('long')
Python Exception <class 'gdb.error'> No type named long.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('i16')
Python Exception <class 'gdb.error'> No type named i16.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('int16_t')
Python Exception <class 'gdb.error'> No type named int16_t.:
Error while executing Python code.
(gdb) break main
Breakpoint 1 at 0x51b0
(gdb) run
Starting program: /home/dc/dbgtest/tester/target/debug/tester
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, 0x00005555555591b0 in main ()
(gdb) show language
The current source language is "auto; currently c".
(gdb) pi gdb.lookup_type('int16_t')
<gdb.Type object at 0x7ff0f0287a80>
(gdb) pi gdb.lookup_type('i16')
Python Exception <class 'gdb.error'> No type named i16.:
Error while executing Python code.
(gdb) pi gdb.lookup_type('long')
<gdb.Type object at 0x7ff0f0287b98>
(gdb)
```

Resolving patch:
diff --git a/pwndbg/gdblib/typeinfo.py b/pwndbg/gdblib/typeinfo.py
--- a/pwndbg/gdblib/typeinfo.py
+++ b/pwndbg/gdblib/typeinfo.py
@@ -25,11 +25,22 @@ def lookup_types(*types):
 
 
 def update():
+    # Workaround for Rust stuff, see https://github.com/pwndbg/pwndbg/issues/855
+    lang = gdb.execute("show language", to_string=True)
+    if "rust" not in lang:
+        restore_lang = None
+    else:
+        gdb.execute("set language c")
+        if '"auto;' in lang:
+            restore_lang = "auto"
+        else:
+            restore_lang = "rust"
+
     module.char = gdb.lookup_type("char")
     module.ulong = lookup_types("unsigned long", "uint", "u32", "uint32")
     module.long = lookup_types("long", "int", "i32", "int32")
     module.uchar = lookup_types("unsigned char", "ubyte", "u8", "uint8")
-    module.ushort = lookup_types("unsigned short", "ushort", "u16", "uint16")
+    module.ushort = lookup_types("unsigned short", "ushort", "u16", "uint16", "uint16_t")
     module.uint = lookup_types("unsigned int", "uint", "u32", "uint32")
     module.void = lookup_types("void", "()")
 
@@ -45,9 +56,9 @@ def update():
     }
 
     module.int8 = lookup_types("char", "i8", "int8")
-    module.int16 = lookup_types("short", "i16", "int16")
+    module.int16 = lookup_types("short", "short int", "i16", "int16")
     module.int32 = lookup_types("int", "i32", "int32")
-    module.int64 = lookup_types("long long", "long", "i64", "int64")
+    module.int64 = lookup_types("long long", "long long int", "long", "i64", "int64")
     module.signed = {1: module.int8, 2: module.int16, 4: module.int32, 8: module.int64}
 
     module.pvoid = void.pointer()
@@ -68,6 +79,10 @@ def update():
         raise Exception("Pointer size not supported")
     module.null = gdb.Value(0).cast(void)
 
+    # Rust workaround part 2
+    if restore_lang:
+        gdb.execute("set language %s" % restore_lang)
+
 
 # TODO: Remove this global initialization, or move it somewhere else
 # Call it once so we load all of the types


Test patch: