1

I have a issue with gdb printf in version 9.1

echo -e '#include<stdio.h> \n int main(){ \n printf("Hello"); \n }' > test.c gcc -g test.c -o test echo 'break test.c:4' > test.gdb echo 'run' >> test.gdb echo 'set $aux = (char*)malloc(256)' >> test.gdb echo 'set $e = strcpy($aux, "abc")' >> test.gdb echo 'printf "%s", $aux' >> test.gdb gdb --batch --command=test.gdb test 

Output with gdb 9.1:

Breakpoint 1 at 0x1167: file test.c, line 4. Breakpoint 1, main () at test.c:4 4 } �e��� 

Expected output (same as gdb v8):

Breakpoint 1 at 0x1167: file test.c, line 4. Breakpoint 1, main () at test.c:4 4 } abc 

I've checked charset, but it seems ok. Any idea about that?

2

1 Answer 1

1

This is Bug 25650 - GDB can't 'printf' a convenience variable holding an inferior address, fixed in gdb 9.2.

If you can't upgrade to gdb 9.2 but can recompile your existing distro's gdb 9.1, there is a two-line patch.

On Ubuntu 20.04, which comes with gdb 9.1-0ubuntu1:

  1. run apt build-dep gdb to haul in the packages needed to build gdb from source
  2. run apt install dpkg-dev (to get /usr/bin/dpkg-source)
  3. uncomment the deb-src lines in /etc/apt/sources.list
  4. run apt update
  5. cd to an empty directory and run apt source gdb . Doing this in a fresh new directory will make it easier to clean things up after the compilation.
  6. cd to gdb-9.1 and apply the patch to gdb/printcmd.c
  7. build and install gdb. For example, to put it in /usr/local/bin, the default, you'd run
 mkdir build cd build ../configure make make install 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.