<div dir="auto"><div dir="auto">would update it </div><div dir="auto"><br></div>Hello what os and architecture was it built on that it gets optimised out ? <div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">How do you check that the position is in 1 instead of 2 in  i586 architecture </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 29 Jul 2021, 12:22 Ralf Habacker via Kde-finance-apps, <<a href="mailto:kde-finance-apps@kde.org">kde-finance-apps@kde.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Am 29.07.21 um 12:49 schrieb Ralf Habacker via Kde-finance-apps:<br>
> Am 28.07.21 um 15:48 schrieb Da Viper via Kde-finance-apps:<br>
>> i am trying to return a string as one of the children in the pretty printer<br>
>><br>
Compiling a test case for QStringRef having<br>
<br>
<br>
   QString a("test)<br>
   QStringRef aRef(&a);<br>
<br>
<br>
with RelWidhDebInfo cmake build type on running gdb 10.1 with your qt<br>
printers enabled I get the following error:<br>
<br>
Traceback (most recent call last):<br>
  File "/usr/share/gdb/python/gdb/printing.py", line 218, in __call__<br>
    return printer.gen_printer(val)<br>
  File "/home/ralf.habacker/src/gdb_printers/printers/qtprinters.py",<br>
line 301, in __init__<br>
    self.index = int(val['m_position'])<br>
gdb.error: value has been optimized out<br>
<br>
<br>
According to<br>
<a href="https://github.com/qt/qtbase/blob/5.15/src/corelib/text/qstring.h#L1602" rel="noreferrer noreferrer" target="_blank">https://github.com/qt/qtbase/blob/5.15/src/corelib/text/qstring.h#L1602</a><br>
QStringRef is defined as<br>
<br>
class Q_CORE_EXPORT QStringRef {<br>
    const QString *m_string;<br>
    int m_position;<br>
    int m_size;<br>
<br>
<br>
m_position is be accessable by using<br>
<br>
(gdb) p ((int*)&aRef)[2]<br>
$3 = 0<br>
<br>
when the target has been compiled for x86_64 architecture and by<br>
<br>
(gdb) p ((int*)&aRef)[1]<br>
$3 = 0<br>
<br>
with i586 architecture.<br>
<br>
<br>
Accessing the referenced string can be done with<br>
<br>
(gdb) p *(QString**)&aRef<br>
$3 = (QString *) 0x7fffffffd6e8<br>
<br>
and the content returned by<br>
<br>
(gdb) p **(QString**)&bRef<br>
$4 = "test"<br>
<br>
Regards<br>
Ralf<br>
</blockquote></div>