UnicodeDecodeError on gdb.execute

Simon Sobisch simonsobisch@gnu.org
Wed Nov 3 20:50:03 GMT 2021

For some special file I need to look at the source code from within the 
GDB extension.

I did this with the reasonable and obious
	output = gdb.execute("list *" + hex(sal.pc), False, True)
(and get more lines with a follow-up "list" [not all are needed, 
otherwise the gdb.parameter("listsize") could be adjusted).

I _think_ the problem I expect now is because of a system with Python3 
which has default utf8 encoding, but it _may_ was also in before: 
There's a python exception UnicodeDecodeError in this line whenever it 
contains "extended" ascii.

"list" in GDB shows the code correctly; also
	(gdb) py gdb.execute("list 14")
shows the correct text, but as soon as python has to internally decode 
it to store a string:
	(gdb) py gdb.execute("list 14", False, True)
	Traceback (most recent call last):
	  File "<string>", line 1, in <module>
	UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in
	position 18: invalid start byte
	Error while executing Python code.

is there any way I could adjust the encoding used for storing 
gdb.execute as string?
Is there a reason that this isn't by default set to match 
gdb.target_charset() ?

Thanks for insights to this issue, too,

More information about the Gdb mailing list