GDB printers: print as string instead of char array

Da Viper yerimyah1 at gmail.com
Wed Aug 4 15:02:33 BST 2021


Hello there i was able to narrow down the problem,

it is that gdb/MI does not print to_string values if it has children.
i am not sure why and do not know any way to change that. If you do
let me know

for example we have two variables

one QString  and QStringList

`QString string("this is a string");`
`QStringList aList{ "one", "two", "three"};`

in gdb/MI if you run `-var-create - * "string"` you would get

^done,name="var6",numchild="0",value="\"this is a
qstring\"",type="QString",thread-id="1",displayhint="string",dynamic="1",has_more="0"

where var6 above is the name of the varobj and value is the `to_string` value.

if you do the same for the qstring list a list
-var-create - * "alist"
you get
done,name="var9",numchild="0",value="{...}",type="QStringList",thread-id="1",displayhint="array",dynamic="1",has_more="1"

here value = "{..}" this is what is shown in the IDE's

also running `-var-evaluate-expression "var6"`  would print the
to_string value where var6 is the variable object name


back to the char array problem,
i thinks it is because of the above problem that the is shown likes that.
as it is meant to print the values and char[array].

do not know how to show the value instead of it showing `{..}`

On Wed, 4 Aug 2021 at 11:35, Ralf Habacker via Kde-finance-apps
<kde-finance-apps at kde.org> wrote:
>
> Am 03.08.21 um 17:24 schrieb Da Viper via Kde-finance-apps:
> > There is a current problem when i try to return a python string as
> > part of a pretty printer children
> >
> > in an gdb cli it prints as a string but in any IDE it does not print
> > as a string it only prints as a char array
> >
> > i checked the internet the only thing is could find is a question in
> > stackoverflow
> > https://stackoverflow.com/questions/26472066/gdb-pretty-printing-returning-string-from-a-childrens-iterator-but-displaye
> >
> > and a bug report in sourceware
> > https://sourceware.org/bugzilla/show_bug.cgi?id=18282
> >
> > you could try what i mean with `QStringRef`  and view the ref_str in
> > kdevelop and IDE
> >
>
> I guess that kdevelop uses the GDB/MI interface to send commands, which
> may have a different behavior compared with command line gdb.
>
> With command line gdb you can enable this mode either by starting gdb
> with the interpreter-exec command as shown in the following example:
>
> $ gdb
> (gdb) interpreter-exec mi "-data-list-register-names"
>
> which returns
>
> -data-list-register-names
> ^done,register-names=["eax","ecx","edx","ebx","esp","ebp","esi","edi","eip","eflags","cs","ss","ds","es","fs","gs","st0","st1","st2","st3","st4","st5","st6","st7","fctrl","fstat","ftag","fiseg","fioff","foseg","fooff","fop","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","mxcsr","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","orig_eax","al","cl","dl","bl","ah","ch","dh","bh","ax","cx","dx","bx","","bp","si","di","mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"]
> (gdb)
>
>
> or by using the --interpreter command line option as shown below
>
> $ gdb --quiet --interpreter mi
> =thread-group-added,id="i1"
> =cmd-param-changed,param="python print-stack",value="full"
> ~"-----------------------------\n"
> (gdb)
>
> Then you can enter mi related commands:
>
>
> -data-list-register-names
> ^done,register-names=["eax","ecx","edx","ebx","esp","ebp","esi","edi","eip","eflags","cs","ss","ds","es","fs","gs","st0","st1","st2","st3","st4","st5","st6","st7","fctrl","fstat","ftag","fiseg","fioff","foseg","fooff","fop","xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","mxcsr","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","orig_eax","al","cl","dl","bl","ah","ch","dh","bh","ax","cx","dx","bx","","bp","si","di","mm0","mm1","mm2","mm3","mm4","mm5","mm6","mm7"]
> (gdb)
>
>
> So see which commands the IDE sends to gdb, in qtcreator you can enable
>  the "Debugger-log" view
> https://doc.qt.io/qtcreator/creator-troubleshooting-debugging.html,
> which shows all sended and received data. You can also enter gdb
> commands directly by the IDE.
>
> For kdevelop I current do not know how to show them. Maybe Thomas can
> point you to the right direction related to this topic.
>
> Regards
> Ralf


More information about the Kde-finance-apps mailing list