Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. how to use expressions in debugger?
Forum Updated to NodeBB v4.3 + New Features

how to use expressions in debugger?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
12 Posts 4 Posters 4.6k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davecotter
    wrote on 4 Aug 2017, 04:54 last edited by
    #1

    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. 0_1501822344686_Screen Shot 2017-08-03 at 9.11.15 PM.png
    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)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 4 Aug 2017, 19:23 last edited by
      #2

      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.

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 5 Aug 2017, 11:03 last edited by
        #3

        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

        1 Reply Last reply
        1
        • D Offline
          D Offline
          davecotter
          wrote on 8 Aug 2017, 01:25 last edited by
          #4

          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:
          0_1502155228833_Screen Shot 2017-08-07 at 6.20.06 PM.png

          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:
          0_1502155129969_Screen Shot 2017-08-07 at 6.16.42 PM.png

          and THAT failed too. every time, no matter what i tried, i only ever see this in the debugger:
          0_1502155480474_Screen Shot 2017-08-07 at 6.22.59 PM.png

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jeremy_k
            wrote on 8 Aug 2017, 07:09 last edited by
            #5

            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 is exec(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)
            

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            2
            • D Offline
              D Offline
              davecotter
              wrote on 8 Aug 2017, 15:04 last edited by
              #6

              i'm pretty sure i'm using python 2.7. also the help text says this:
              0_1502204648512_Screen Shot 2017-08-08 at 8.03.35 AM.png

              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

              J 1 Reply Last reply 9 Aug 2017, 03:30
              0
              • D davecotter
                8 Aug 2017, 15:04

                i'm pretty sure i'm using python 2.7. also the help text says this:
                0_1502204648512_Screen Shot 2017-08-08 at 8.03.35 AM.png

                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

                J Offline
                J Offline
                jeremy_k
                wrote on 9 Aug 2017, 03:30 last edited by jeremy_k 8 Sept 2017, 06:37
                #7

                @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})

                Asking a question about code? http://eel.is/iso-c++/testcase/

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  davecotter
                  wrote on 10 Aug 2017, 20:57 last edited by davecotter 8 Oct 2017, 22:02
                  #8

                  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)
                  
                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jeremy_k
                    wrote on 11 Aug 2017, 01:46 last edited by
                    #9

                    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.

                    Asking a question about code? http://eel.is/iso-c++/testcase/

                    1 Reply Last reply
                    2
                    • D Offline
                      D Offline
                      davecotter
                      wrote on 11 Aug 2017, 05:44 last edited by
                      #10

                      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)
                      
                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        davecotter
                        wrote on 12 Aug 2017, 04:00 last edited by
                        #11

                        is this "feature" just not working at all? does anyone have it working?

                        M 1 Reply Last reply 12 Aug 2017, 08:35
                        0
                        • D davecotter
                          12 Aug 2017, 04:00

                          is this "feature" just not working at all? does anyone have it working?

                          M Offline
                          M Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on 12 Aug 2017, 08:35 last edited by mrjj 8 Dec 2017, 08:36
                          #12

                          @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.

                          1 Reply Last reply
                          1

                          1/12

                          4 Aug 2017, 04:54

                          • Login

                          • Login or register to search.
                          1 out of 12
                          • First post
                            1/12
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved