[英]How to calculate the true square root of a number with 3 user-defined functions
[英]gdb user-defined functions: how to pass complex argument?
我想檢查幾個QString變量,所以我在Internet上找到了這個宏:
define printqstring
printf "(QString)0x%x (length=%i): \"",&$arg0,$arg0.d->size
set $i=0
while $i < ($arg0).d->size
set $c=$arg0.d->data[$i++]
if $c < 32 || $c > 127
printf "\\u0x%04x", $c
else
printf "%c", (char)$c
end
end
printf "\"\n"
end
但是當我嘗試使用它時,出現了這樣的錯誤:
(gdb) printqstring ((MyWidget *)0xd98cb0)->caption_
A syntax error in expression, near `,((MyWidget.d->size'.
如果我嘗試手動使用宏命令,它們可以正常工作:
(gdb) printf "(QString)0x%x (length=%i): \"",&((MyWidget *)0xd98cb0)->caption_,((MyWidget *)0xd98cb0)->caption_.d->size
(QString)0xd98ccc (length=3)
那么如何將這樣復雜的參數傳遞給gdb宏呢?
不幸的是,gdb總是在任何空格字符處將輸入划分為用戶定義的函數,即使該字符位於括號內或類似的內容內。
因此,您可以確保不要在要傳遞的參數中使用任何空格:
(gdb) printqstring ((MyWidget*)0xd98cb0)->caption_
^~~ removed space
我不知道有什么好方法可以使此操作更加方便並留出空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.