简体   繁体   English

gdb用户定义函数:如何传递复杂参数?

[英]gdb user-defined functions: how to pass complex argument?

I want to examine several QString variables, so I found macros for this in Internet: 我想检查几个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

But when I try to use it, I got such error: 但是当我尝试使用它时,出现了这样的错误:

(gdb) printqstring ((MyWidget *)0xd98cb0)->caption_
A syntax error in expression, near `,((MyWidget.d->size'.

if I try to use commands from macros by hand, they work fine: 如果我尝试手动使用宏命令,它们可以正常工作:

(gdb) printf "(QString)0x%x (length=%i): \"",&((MyWidget *)0xd98cb0)->caption_,((MyWidget *)0xd98cb0)->caption_.d->size
(QString)0xd98ccc (length=3)

So how can I pass such complex argument to gdb macros? 那么如何将这样复杂的参数传递给gdb宏呢?

Unfortunately gdb always divides input to a user-defined function at any space character, even if that character is inside parentheses or something like that. 不幸的是,gdb总是在任何空格字符处将输入划分为用户定义的函数,即使该字符位于括号内或类似的内容内。

So you can just make sure you don't use any spaces in the argument you want to pass: 因此,您可以确保不要在要传递的参数中使用任何空格:

(gdb) printqstring ((MyWidget*)0xd98cb0)->caption_
                             ^~~ removed space

I don't know of any good way to make this more convenient and allow spaces. 我不知道有什么好方法可以使此操作更加方便并留出空间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 3 个用户定义函数计算数字的真实平方根 - How to calculate the true square root of a number with 3 user-defined functions 如何使用IOCP将用户定义的数据传递给工作线程? - How to pass user-defined data to a worker thread using IOCP? 如何传递大小为用户定义的二维数组 - How to pass a 2-D array whose size is user-defined 如何将默认参数传递给用户定义的类类型的参数? - can I pass default argument to parameter of user-defined class type? C++ 中复杂用户定义类型的 RVO - RVO for complex user-defined types in C++ C ++如何在类构造函数中使用另一个(用户定义的)类作为参数 - C++ How to use another (user-defined) class as an argument in a class constructor 如何用用户定义的函数覆盖 C lib 函数,如 _sbrk? - How to override C lib functions like _sbrk with user-defined one? Function 模板参数推导与用户定义的转换运算符 - Function template argument deduction with user-defined conversion operator 用于双参数构造函数的用户定义文字 - User-Defined Literal for Two-Argument Constructor 用户定义的文字与uint64_t参数结合使用 - user-defined literals combined with an uint64_t argument
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM