所以在組裝我聲明如下字符串:大會GDB打印字符串
Sample db "This is a sample string",0
在GDB I型 「P樣品。」(不含引號),它吐出0x73696854。我想要打印出實際的字符串。所以我嘗試了「printf」%s「Sample」(再次沒有引號),並且吐出了「無法訪問地址0x73696854處的內存」。
簡版: 如何在GDB中打印字符串?
所以在組裝我聲明如下字符串:大會GDB打印字符串
Sample db "This is a sample string",0
在GDB I型 「P樣品。」(不含引號),它吐出0x73696854。我想要打印出實際的字符串。所以我嘗試了「printf」%s「Sample」(再次沒有引號),並且吐出了「無法訪問地址0x73696854處的內存」。
簡版: 如何在GDB中打印字符串?
我的老師剛給我發了郵件。對於任何想知道的人:
p(char[20]) Sample
其中20是要打印的字符數。
要打印C風格NUL
封端的字符串,你也應該能夠做到這一點:
print (char*) &Sample
printf "%s", &Sample
我有同樣的問題!試試這個:
x/s &Sample # prints the whole string
「x」 - 通常用於檢查數據。
對於一個勁兒地,你可以憂色這個代碼
x/c &Sample # prints: "T"
如果你想看到多個字符,你可以給希望的字符數
x/3c &Sample # prints: "T" "h" "i"