0

Please see ADD(solved) below.

While debugging linux booting on a qemu virtual machine, I wanted to print the log buffer at some point. (printk write to the buffer called __log_buf and the contents are flushed out to serial port when serial port is available). At a point where the buffer has many characters (more than 500 hundreds ) I tried printing the __log_buf.

(gdb) p __log_buf $1 = "\200\377\377\377\000\000\000\000Booting Linux on physical CPU 0x0000000000 [0x000f0510]\000\201\377\377\377\000\000\000\000Linux version 5.10.0-rc5 (ckim@ckim-ubuntu) (aarch64-none-elf-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (ar"...
(gdb) p __log_buf[0]@500 $4 = "\200\377\377\377\000\000\000\000Booting Linux on physical CPU 0x0000000000 [0x000f0510]\000\201\377\377\377\000\000\000\000Linux version 5.10.0-rc5 (ckim@ckim-ubuntu) (aarch64-none-elf-gcc (GNU Toolchain for the A-profile Architecture 10.2-2020.11 (ar"...

Note the \000 means 0x00 value. I counted the charaters. It's only 202 characters. I searched the gdb options but couldn't find any. I tried 'set max-completions 500'(I don't understand what max-completion is). How can increase the number of printed characters?

ADD (solved) - a little different from the duplicate Q&A :
(solved) I found doing set print elements 0 and doing p __log_buf does the job. The printf didn't work for me maybe I'm using gdb inside ddd. I'' redirect my question to the proposed answer by Ajay with this info added in the question. Thanks all!
p.s. : if you are using ddd (data-display-debugger) and if the ddd hangs after start. Edit ~/.ddd/init and change set extended_prompt not set \n\ to set extended_prompt (gdb) \n\ and things will be ok again.

Chan Kim
  • 5,177
  • 12
  • 57
  • 112
  • Thanks, but that doesn't work. I tried `(gdb) printf "%s\n",__log_buf` but it doesn't print anything. I tried `set print elements 0` or `set print elements 500` before that too. – Chan Kim Mar 11 '22 at 14:24
  • Both methods (`set print elements 0` and `printf "%s",...`) work for me, using GDB 10.2 on Windows 10, but granted, for a pure C string without embedded `'\0'`. – the busybee Mar 11 '22 at 14:42
  • After writing comment above, I found just doing `p __log_buf` prints the very long string as I wanted. I think this is the result of `set print elements 0`. I'm using gdb inside ddd (data display debugger). I was very pleased that I can do some debug, but now, when I start ddd, it hangs at the start without showing the `tip of the day` window so I can't try it again. In the past `set extended_prompt not set` to `set extended_prompt (gdb)` in ~/.ddd/init fixed the start-hang but maybe this is another case. – Chan Kim Mar 11 '22 at 14:48
  • -continued: I don't know why this new problem came about. (probably the commands I entered during this problem). – Chan Kim Mar 11 '22 at 14:48
  • (solved) I found doing `set print elements 0` and doing `p __log_buf` does the job. The printf didn't work for me maybe I'm using gdb inside ddd. I'' redirect my question to the proposed answer by Ajay with this info added in the question. Thanks all! – Chan Kim Mar 11 '22 at 14:58
  • @ChanKim I think the printf didn't work because printf stops at `\0`, which is the 5th character in your string. – Ajay Brahmakshatriya Mar 11 '22 at 15:02
  • @AjayBrahmakshatriya yes that seems so. I didn't catch that. But the `print(=p)` works when there are null characters. – Chan Kim Mar 11 '22 at 15:03

0 Answers0