簡體   English   中英

如何計算要用於gdb監視命令的表達式?

[英]How to evaluate an expression to be used for a gdb monitor command?

在腳本化的gdb會話中,我想使用monitor <cmd> ,其中cmd應包含符號的地址。 例如:

monitor foobar &myVariable

應該變成:

monitor foobar 0x00004711

因為遠程無法評估表達式。 無論我如何嘗試,都會發送字符串“&myVariable”而不是地址。

我玩弄便利變量和東西,但這是我發現的唯一解決方法:

# write the command into a file and execute this file
# didn't find a direct way to include the address into the monitor command
set logging overwrite on
set logging on command.tmp
printf "monitor foobar 0x%08x\n", &myVariable
set logging off
source command.tmp

有什么想法可以更優雅地解決這個問題嗎?

最簡單的方法是使用gdb eval命令,此命令正是出於此目的而引入的。 它的工作原理類似於printf

(gdb) eval "monitor foobar %p", &myVariable

(我實際上沒有嘗試過,所以要小心。)

如果您的gdb沒有eval ,那么它就偏舊了。 我建議升級。

如果您無法升級,則還可以使用Python編寫腳本。

如果您的gdb沒有Python,那么它要么很舊(升級!),要么在沒有Python支持的情況下進行了編譯(重新編譯!)。

如果您無法獲得這些功能中的任何一個,那么恐怕剩下的就是“寫出腳本並提供source ”的方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM