简体   繁体   中英

gdb print won't print out something readable from my char array

i have a char buffer[100] and i'm trying to use gdb to read the contents out of it at various stages of runtime.

i use p buffer and i get

"/*\000\000\000\000\000\000????X?o\000\025\202\004\b", '\0' <repeats 12 times>, ".N=?", '\0' <repeats 24 times>, "`\203\004\b\000\000\000\000L\227\004\bX????\202\004\b?\017\204\000\f?\203\000\210???i\205\004\b??r"

how do i get p to convert it into a readable format???

x/s buffer应该将数组的内容显示为空终止字符串(这是我假设你喜欢的)。

If you want to get rid of the junk after the terminating null (so you'll just see "/*" for this string) you can use:

p (char*)buffer

At the moment gdb is printing your variable as an array, so it's showing all 100 characters; casting it to char* makes it print it as a C string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM