简体   繁体   中英

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

I want to examine several QString variables, so I found macros for this in 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?

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.

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.

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