cs01 / cs01/gdbgui

unicode error when view source file which is not utf-8 encoded

Open
#292 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10.4k
Forks
521
PR merge metrics
No merged PRs in 30d

Description

I encountered this issue when I attempt to open cp949 encoded file. I think same issue would occur with shift-jis encoded file and these can be easily reproduced.

![output](https://user-images.githubusercontent.com/1835950/64578176-97c21400-d3b9-11e9-98ee-c883728b960d.png)
```'utf-8' codec can't decode byte 0xc0 in position ~```

The problem is in ```backend.py:read_file``` method. In here, it attempts to read source file with default ```open()``` method, which reads file as unicode by default. Exception occurs when file is not in unicode. I think ```codecs.open``` with correct encoding option is necessary. correct encoding shall be passed with gdbgui parameter or use session environment variable.

Currently I modified ```backend.py:689``` line to set encoding from my environment variable and no problem.
```
...
sys_enc = os.getenv('LC_ALL', 'utf-8')
with codecs.open(path, "r", encoding=sys_enc) as f:
...
```

Environments are,
Ubuntu 14.04
gdbgui 0.13.2.0 (downloaded from pip)
gdb 8.2
firefox 66.0.3

Thanks.

ps. Fixed error message as previous one was incorrect.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.