Fixing the encoding problem using gef plugin for gdb on Ubuntu 20.04 Docker container.
Problem Discription
This blog presents a command line problem caused by locales (language settings) on Linux systems like Ubuntu as well as fixing this problem by correctly configuring language environment variabels.
The first time entering a clean Ubuntu container, you might configure nothing about language settings. When type locale
on terminal, you might get this:
Then, something goes wrong after installing gdb and gef plugin:
Python Exception <class 'UnicodeEncodeError'> 'ascii' codec can't encode character '\u27a4' in position 12: ordinal not in range(128):
Problem Fixing
Install Dependencies
As mentioned above, the reason is language settings on command line variables. Here comes some solutions to fix it. First of all, check and install available locales.
❯ locale -a
C
C.UTF-8
POSIX
If the locale you need does not appear in this list (e.g. en_US.utf8), use the following command to install it additionally.
❯ apt install locale-gen
❯ locale-gen en_US.UTF-8
Generating locales (this might take a while)...
en_US.UTF-8... done
Generation complete.
# This command is for displaying a list of all available locales.
❯ cat /usr/share/i18n/SUPPORTED
Adjusting Locales
The default settings are stored in the /etc/default/locale
file.
❯ cat /etc/default/locale
# File generated by update-locale
LANG=en_US.UTF-8
This file can either be adjusted manually or updated using command update-locale
.
❯ update-locale LANG=en_US.UTF-8
Besides, another solution to fix this problem is configuring ~/.bashrc
file.
export LANG=en_US.utf8
export LC_ALL=en_US.utf8
Reboot system and gef works well.