Unsolved how to use expressions in debugger?
-
eg: i have a struct "SuperString" and i want the debugger to always just show one of it's elements without my having to disclose the whole struct.
In the above screen shot, "itemStr" is a "SuperString &", i want all SuperStrings to always just show the "i_std" element, but on the line where it says "itemStr", without having to twirl down the little disclosure triangle. in Xcode i can enter "{$VAR.i_std}:s" as the expression, and get what i want. how do i do that in Qt Creator? (solutions for both mac and windows please) -
I belive there is no build-in solution to show all SuperString like you want, but you can add a variable that only shows i_std: just right click in the watches windows, choose "New expression evaluator" and then enter itemStr.i_std and press Ok.
As the debugger uses Python to display all variables, there might also be a way to achive exactly what you want, but I can't help you therer.
-
to add to @aha_1980
If you are feeling adventurous you could make such "view" yourself
http://doc.qt.io/qtcreator/creator-debugging-helpers.html -
I'm feeling simultaneously adventurous and frustrated.
i'm on a mac, so i'm pretty sure that's Python 2.7
So here's my helper python file:
then went to get that to run by going to:
Preferences (tools) -> debugger -> gdb -> additional startup commands:first i tried this:
python execfile('%{CurrentProject:NativePath}/../../xplat/python/qt_debug_helpers.py')
then this:
python execfile(%{CurrentProject:NativePath}'/../../xplat/python/qt_debug_helpers.py')
then just this:
python execfile('/Users/davec/Developer/depot/kJams/Development/xplat/python/
to no avail! finally i gave up and tried this:
and THAT failed too. every time, no matter what i tried, i only ever see this in the debugger:
-
The documentation for adding debugger dumpers appears to be stale. I hit a few problems. Errors are buried in the debugger log, and not necessarily fatal.
-
Python's execfile() is removed in Python 3.
The recommended replacement isexec(open(filename).read())
.
https://docs.python.org/3.5/whatsnew/3.0.html?highlight=execfile -
The dumper needs to be registered after defined.
theDumper.registerDumper('qdump_MyClass', qdump_MyClass)
theDumper is a global variable in the gdb bridge code. The lldb version is lldb.theDumper.
Fixing these issues resulted in a working dumper for me using the "Additional Startup Commands" input in the debugger options. The "Additional Attach Commands" and "Debugging Helper Customization" inputs didn't work.
The python dumper that worked for me on a Linux host is
def qdump__MyClass(d, value): d.putValue("This is a custom item dumper") d.putNumChild(0) theDumper.registerDumper('qdump__MyClass', qdump__MyClass)
-
-
i'm pretty sure i'm using python 2.7. also the help text says this:
so this is my script now
import dumper def qdump__SuperString(d, value): d.putNumChild(0) d.putValue("Yay, Foo works :)") dumper.registerDumper('qdump__SuperString', qdump__SuperString)
still doesn't work
-
@davecotter said in how to use expressions in debugger?:
i'm pretty sure i'm using python 2.7. also the help text says this:
That message is from Creator, not the debugger.
http://code.qt.io/cgit/qt-creator/qt-creator.git/tree/src/plugins/debugger/gdb/gdboptionspage.cpp#n169
Creator 4.2.2 on my system displays the same message, and the copy of gdb it is using exposes a python 3 interface.In the debugger log view, enter:
python import sys; print(sys.version_info)
The response:
sys.version_info(major=3, minor=5, micro=3, releaselevel='final', serial=0)\n
so this is my script now
import dumper def qdump__SuperString(d, value): d.putNumChild(0) d.putValue("Yay, Foo works :)") dumper.registerDumper('qdump__SuperString', qdump__SuperString)
still doesn't work
Is the dumper object called dumper, and not theDumper or lldb.theDumper? There should be references to it in the debugger log, such as:
python theDumper.loadDumpers({"token":79})
-
on mac i get this:
<10executeDebuggerCommand({"command":"python import sys; print(sys.version_info)","token":10}) >(lldb) script theDumper.executeDebuggerCommand({"command":"python import sys; print(sys.version_info)","token":10}) >@ >token("10")@ >@ >success="0",output="",error="error: 'python' is not a valid command. >error: Unrecognized command 'python'. >"@
on windows i get this:
eERROR: Attempt to issue command "python import sys; print(sys.version_info)" to non-accessible session (InferiorRunOk)
-
Lldb appears to use a different mechanism to invoke the python interpreter. Likewise for CDB. Unfortunately I don't have either available at the moment. The Windows error looks a little like what gdb responds with if there isn't a process being debugged.
The debugger log window might reveal the technique used. With GDB, there are several instances of python python_statement while running a hello world. python sys.path.insert(...), python from gdbbridge import *, python theDumper.loadDumpers({"token":14}), etc.
-
my previous post showed all the info from the debugger log window. also: on windows, i'm definitely running, and debugging my app, however the app was running, not paused. when i pause the app, i get this:
python import sys; print(sys.version_info) ^ pass count must be preceeded by whitespace error in 'python import sys; print(sys.version_info)'
i get the same message on mac whether i am paused or not
below are the full logs if that helps, it's greek to me:
mac:
1loadDumpers({"token":1}) 2setupInferior({"attachpid":0,"breakonmain":0,<environment suppressed>,"executable":"/Users/davec/Developer/depot/kJams/Development/qt/build/mac/kJams 2 Debug.app/Contents/MacOS/kJams 2 Debug","nativemixed":0,"platform":"","processargs":[],"remotechannel":"","startmode":1,"sysroot":"","token":2,"useterminal":0,"workingdirectory":"/Users/davec/Developer/depot/kJams/Development/qt/build/mac"}) ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/lib/QtWidgets.framework/Versions/5/QtWidgets empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/lib/QtGui.framework/Versions/5/QtGui empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/lib/QtCore.framework/Versions/5/QtCore empty dSYM file detected, dSYM was created with an executable with no debug info. 3runEngine({"token":3}) ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/platforms/libqcocoa.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqgif.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqicns.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqico.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqjpeg.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqmacjp2.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqsvg.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/lib/QtSvg.framework/Versions/5/QtSvg empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqtga.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqtiff.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqwbmp.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. ERROR: Lldb stderr: warning: (x86_64) /Users/davec/Developer/Qt/5.9.1/clang_64/plugins/imageformats/libqwebp.dylib empty dSYM file detected, dSYM was created with an executable with no debug info. 4executeDebuggerCommand({"command":"python import sys; print(sys.version_info)","token":4}) 5interruptInferior({"token":5}) 6fetchThreads({"token":6}) 7fetchStack({"context":"","nativemixed":0,"stacklimit":20,"token":7}) 8activateFrame({"index":14,"thread":2886007,"token":8}) 9fetchVariables({"autoderef":1,"context":"","displaystringlimit":"100","dyntype":1,"expanded":["local","watch","return","inspect"],"fancy":1,"formats":{"local.bitEndianL":23,"local.ch":23,"local.objectName.i_ref":1},"nativemixed":0,"partialvar":"","passexceptions":0,"qobjectnames":1,"stringcutoff":"10000","token":9,"typeformats":{},"watchers":[]}) <Rebuild Watchmodel 1 @ 22:37:15.871 > 10executeDebuggerCommand({"command":"python import sys; print(sys.version_info)","token":10})
win:
l+t l+s bu100100 `kJams_2_Debug!Z:\Users\davec\Developer\depot\kJams\Development\xplat\proj\win\src\FSRefUtils_Win.cpp:1806` !qtcreatorcdbext.breakpoints -v sxn 0x4000001f sxn ibp .asm source_line !qtcreatorcdbext.setparameter maxStringLength=10000 maxStackDepth=20 !qtcreatorcdbext.script print(sys.version) !qtcreatorcdbext.pid bu100102 0x7ff7a8541724 bu100101 0x7ff7a8541710 !qtcreatorcdbext.breakpoints -v !qtcreatorcdbext.script sys.path.insert(1, 'C:\\Users\\davec\\dev\\Qt\\Tools\\QtCreator\\share\\qtcreator\\debugger') !qtcreatorcdbext.script from cdbbridge import Dumper !qtcreatorcdbext.script print(dir()) !qtcreatorcdbext.script theDumper = Dumper() !qtcreatorcdbext.script theDumper.loadDumpers(None) g ERROR: Attempt to issue command "python import sys; print(sys.version_info)" to non-accessible session (InferiorRunOk) ~0 s !qtcreatorcdbext.stack unlimited lm m wow64 .frame 0xa !qtcreatorcdbext.script theDumper.fetchVariables({"autoderef":1,"context":"","displaystringlimit":"100","dyntype":1,"expanded":["local","watch","return","inspect"],"fancy":1,"formats":{"local.fileStr.i_uni.i_nameP":10,"local.objectName.i_uni.i_nameP":10,"local.valueP":1},"nativemixed":0,"partialvar":"","passexceptions":0,"qobjectnames":1,"stringcutoff":"10000","typeformats":{},"uninitialized":[],"watchers":[]}) <Rebuild Watchmodel 1 @ 22:37:43.024 > python import sys; print(sys.version_info)
-
is this "feature" just not working at all? does anyone have it working?
-
@davecotter
Hi
Been here for some years now. You are the first poster I saw about a custom
debug script. I never tried myself and i have zero experience with macs and the
dylib system. But since Creator itself utilizing such scripts, it does seem to work regardless of this case's issues.