Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...

QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcreatordebug windowarrayindexdisplay
11 Posts 5 Posters 1.2k Views
  • 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.
  • C Offline
    C Offline
    Cedric-air
    wrote on 5 Jan 2024, 09:26 last edited by Cedric-air 1 May 2024, 09:33
    #1

    In my program's i have arrays of data, with enums describing the meaning like this:

    typedef enum {
        ITEM_0 = 0,
        ITEM_1,
        ITEM_2,
        ITEMS_ARRAY_SIZE,
    }ITEMS_ENUM;
    
    uint32_t myItems[ITEMS_ARRAY_SIZE];
    

    Then in my code I can access a place in the array like this:

    myItems[ITEM_0] = 34;
    

    The debugger doesn't understand the indexes of the array are coming from an enum, and therefore displays the value of the array like this:

    myItems  value  type
    [0]            34       uint32_t
    

    It would be nice if the debugger would show it like this:

    myItems  value  type
    [ITEM_0]            34       uint32_t
    

    For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array. Of course this doesn't work for every situation, so we also need a way to switch back from enum display to 0,1,2,3... display.

    I'm looking for a solution that works with standard C enums and arrays, as I'm using Qt to run and debug legacy C programs. Therefore I can't (easily) use C++ constructions to achieve this.

    My versions:
    Qt Creator 12.0.1
    Based on Qt 6.6.1 (GCC 13.2.1 20230801, x86_64)
    $ uname -a
    Linux cedric 6.6.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 14 Dec 2023 03:45:42 +0000 x86_64 GNU/Linux

    dbfe17f2-9b84-4a11-8a30-e784bb315e15-image.png

    708a7f76-c0e8-4026-b777-4a8844b024b6-image.png

    mainwindow.cpp (the other project files are default)

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    typedef enum {
        ITEM_0 = 0,
        ITEM_1,
        ITEM_2,
        ITEMS_ARRAY_SIZE,
    }ITEMS_ENUM;
    
    uint32_t myItems[ITEMS_ARRAY_SIZE];
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        myItems[ITEM_0] = 34;
        myItems[ITEM_1] = 16;
        myItems[ITEM_2] = 45;
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    1 Reply Last reply
    0
    • J Offline
      J Offline
      JonB
      wrote on 5 Jan 2024, 09:31 last edited by JonB 1 May 2024, 09:34
      #2

      @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

      For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array.

      Do you know of any C++ debugger which does this? (I certainly do not, C/C++ arrays are indexed by integer not enumerated types.)

      Are you making a suggestion for the devs to change the behaviour of Creator (or even of gdb)? In which case be aware that posting here is not going to cause that.

      C 1 Reply Last reply 5 Jan 2024, 09:37
      0
      • J JonB
        5 Jan 2024, 09:31

        @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

        For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array.

        Do you know of any C++ debugger which does this? (I certainly do not, C/C++ arrays are indexed by integer not enumerated types.)

        Are you making a suggestion for the devs to change the behaviour of Creator (or even of gdb)? In which case be aware that posting here is not going to cause that.

        C Offline
        C Offline
        Cedric-air
        wrote on 5 Jan 2024, 09:37 last edited by
        #3

        @JonB said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

        @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

        For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array.

        Do you know of any C++ debugger which does this?

        I don't know any C nor C++ debugger which does this.

        Are you making a suggestion for the devs to change the behaviour of Creator (or even of gdb)? In which case be aware that posting here is not going to cause that.

        I am indeed making a suggestion for the devs to change the behavior of QtCreator (or even of gdb). What can I do to cause such a change? What's a better place to post this suggestion?

        J J 2 Replies Last reply 5 Jan 2024, 09:42
        0
        • C Cedric-air
          5 Jan 2024, 09:37

          @JonB said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

          @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

          For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array.

          Do you know of any C++ debugger which does this?

          I don't know any C nor C++ debugger which does this.

          Are you making a suggestion for the devs to change the behaviour of Creator (or even of gdb)? In which case be aware that posting here is not going to cause that.

          I am indeed making a suggestion for the devs to change the behavior of QtCreator (or even of gdb). What can I do to cause such a change? What's a better place to post this suggestion?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 5 Jan 2024, 09:42 last edited by
          #4

          @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

          What can I do to cause such a change

          Post it here https://cc-github.bmwgroup.net/swh/adp/pull/154534 if it is for QtCreator.
          If it is for GDB, then research where to post change requests for GDB.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          C 1 Reply Last reply 5 Jan 2024, 10:47
          0
          • C Cedric-air
            5 Jan 2024, 09:37

            @JonB said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

            @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

            For this to work, the Qt debugger should first see the size of the array is an element of an enum, and then assume the rest of the values of the enum are used to name the indexes of the array.

            Do you know of any C++ debugger which does this?

            I don't know any C nor C++ debugger which does this.

            Are you making a suggestion for the devs to change the behaviour of Creator (or even of gdb)? In which case be aware that posting here is not going to cause that.

            I am indeed making a suggestion for the devs to change the behavior of QtCreator (or even of gdb). What can I do to cause such a change? What's a better place to post this suggestion?

            J Offline
            J Offline
            JonB
            wrote on 5 Jan 2024, 09:44 last edited by JonB 1 May 2024, 09:45
            #5

            @Cedric-air
            For a change to Creator you would need to raise it at https://bugreports.qt.io/, or even join the developers' discussion group to pre-discuss your suggestion. [ @jsulm's post crossed with this, you may use whatever link he supplies.]

            For gdb you would need to do similar in a gdb developers forum.

            I would suggest neither of these are going to change their behaviour at this point, but that's for you to discover.

            I am not sure that the Creator debugging could do this even if it wanted to. Creator does not have its own debugger, it sits atop gdb/gdbserver. And I don't think those would supply any information along the lines of "the source code declared the array size using a value from an enumerated type" (as opposed to an integer, which it got converted to) for the debugging engine to even be aware of.

            1 Reply Last reply
            1
            • J jsulm
              5 Jan 2024, 09:42

              @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

              What can I do to cause such a change

              Post it here https://cc-github.bmwgroup.net/swh/adp/pull/154534 if it is for QtCreator.
              If it is for GDB, then research where to post change requests for GDB.

              C Offline
              C Offline
              Cedric-air
              wrote on 5 Jan 2024, 10:47 last edited by
              #6

              @jsulm said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

              @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

              What can I do to cause such a change

              Post it here https://cc-github.bmwgroup.net/swh/adp/pull/154534 if it is for QtCreator.
              If it is for GDB, then research where to post change requests for GDB.

              https://cc-github.bmwgroup.net/swh/adp/pull/154534 is a dead link. I've posted it here instead:
              https://bugreports.qt.io/browse/QTCREATORBUG-30160

              C 1 Reply Last reply 5 Jan 2024, 10:55
              0
              • C Cedric-air
                5 Jan 2024, 10:47

                @jsulm said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

                @Cedric-air said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

                What can I do to cause such a change

                Post it here https://cc-github.bmwgroup.net/swh/adp/pull/154534 if it is for QtCreator.
                If it is for GDB, then research where to post change requests for GDB.

                https://cc-github.bmwgroup.net/swh/adp/pull/154534 is a dead link. I've posted it here instead:
                https://bugreports.qt.io/browse/QTCREATORBUG-30160

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 5 Jan 2024, 10:55 last edited by Christian Ehrlicher 1 May 2024, 10:56
                #7

                @Cedric-air t.b.h. I would expect that the debugger is using the enum types as it does now - an array is indexed by an integral, not an enum. And it's for sure not a QtCreator bug as @JonB already explained to you.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                A 1 Reply Last reply 5 Jan 2024, 21:18
                2
                • C Christian Ehrlicher
                  5 Jan 2024, 10:55

                  @Cedric-air t.b.h. I would expect that the debugger is using the enum types as it does now - an array is indexed by an integral, not an enum. And it's for sure not a QtCreator bug as @JonB already explained to you.

                  A Offline
                  A Offline
                  Axel Spoerl
                  Moderators
                  wrote on 5 Jan 2024, 21:18 last edited by
                  #8

                  @Cedric-air
                  IMHO the issue is very simple.
                  You are using a standard array, which most likely has an index of the type size_t. Whatever you use as a replacement for that type, will be implicitly cast to size_t. The debugger will debug a size_t value, because the array index is of that type. That is how gdb is implemented, and I don’t see an alternative suggestion could have any merits. How should the array know about the enum?

                  What can be done, is implementing your own array as a template. Its index could be typed to your enum and would be debugged accordingly.

                  Software Engineer
                  The Qt Company, Oslo

                  J 1 Reply Last reply 5 Jan 2024, 21:33
                  1
                  • A Axel Spoerl
                    5 Jan 2024, 21:18

                    @Cedric-air
                    IMHO the issue is very simple.
                    You are using a standard array, which most likely has an index of the type size_t. Whatever you use as a replacement for that type, will be implicitly cast to size_t. The debugger will debug a size_t value, because the array index is of that type. That is how gdb is implemented, and I don’t see an alternative suggestion could have any merits. How should the array know about the enum?

                    What can be done, is implementing your own array as a template. Its index could be typed to your enum and would be debugged accordingly.

                    J Offline
                    J Offline
                    JonB
                    wrote on 5 Jan 2024, 21:33 last edited by JonB 1 May 2024, 21:34
                    #9

                    @Axel-Spoerl said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

                    What can be done, is implementing your own array as a template. Its index could be typed to your enum and would be debugged accordingly.

                    Have you actually tried this (not saying you haven't) to address what the OP is asking for? I might have a look at it tomorrow....

                    It's not a question of showing a value as an enumerated value, the OP wants the indexes into an array to be shown as such in the debugger's Watch pane. I imagine that handling of showing the available indexes as a sub-list of an array-type variable must be a feature of debugger code, and I would have thought (guess) it would be constrained to showing integers increasing from 0, no?

                    A 1 Reply Last reply 5 Jan 2024, 21:40
                    0
                    • J JonB
                      5 Jan 2024, 21:33

                      @Axel-Spoerl said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

                      What can be done, is implementing your own array as a template. Its index could be typed to your enum and would be debugged accordingly.

                      Have you actually tried this (not saying you haven't) to address what the OP is asking for? I might have a look at it tomorrow....

                      It's not a question of showing a value as an enumerated value, the OP wants the indexes into an array to be shown as such in the debugger's Watch pane. I imagine that handling of showing the available indexes as a sub-list of an array-type variable must be a feature of debugger code, and I would have thought (guess) it would be constrained to showing integers increasing from 0, no?

                      A Offline
                      A Offline
                      Axel Spoerl
                      Moderators
                      wrote on 5 Jan 2024, 21:40 last edited by
                      #10

                      @JonB
                      Qt Creator uses ptrace and gdb/lldb for that purpose. And an array index is just an int, or size_t, depending on C++ version and compiler. Re-translating that back into an enum, goes a long way. I doubt it will be implemented. But I may be wrong…

                      Software Engineer
                      The Qt Company, Oslo

                      J 1 Reply Last reply 5 Jan 2024, 21:43
                      0
                      • A Axel Spoerl
                        5 Jan 2024, 21:40

                        @JonB
                        Qt Creator uses ptrace and gdb/lldb for that purpose. And an array index is just an int, or size_t, depending on C++ version and compiler. Re-translating that back into an enum, goes a long way. I doubt it will be implemented. But I may be wrong…

                        J Offline
                        J Offline
                        JonB
                        wrote on 5 Jan 2024, 21:43 last edited by
                        #11

                        @Axel-Spoerl said in QtCreator debugger: display enum texts when used as array indexes, instead of 0,1,2...:

                        Re-translating that back into an enum, goes a long way. I doubt it will be implemented.

                        Which is all I said :)

                        1 Reply Last reply
                        1

                        5/11

                        5 Jan 2024, 09:44

                        • Login

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