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. Wrong char type detection in debugger
Forum Updated to NodeBB v4.3 + New Features

Wrong char type detection in debugger

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
debugqt creator
3 Posts 3 Posters 879 Views 1 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.
  • j1eloJ Offline
    j1eloJ Offline
    j1elo
    wrote on last edited by j1elo
    #1

    Hi,
    I cannot make Qt Creator debugger view to correctly detect my char types when the type is behind a typedef.
    I made tests with char *, gchar *, and a custom mychar *, but Qt Creator only detects and shows the text contents for the very first case; it fails to show the other two. Is this a bug?

    Tested with this minimal program:

    main.c

    #include <stdio.h>
    #include <glib.h>
    int main() {
      typedef char mytype;
      
      char *text1 = "TEXT1\n";
      gchar *text2 = "TEXT2\n";
      mytype *text3 = "TEXT3\n";
    
      return 0;
    }
    

    CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)
    project(qtcreator_gchar)
    add_executable(${PROJECT_NAME} "main.c")
    
    find_package(PkgConfig REQUIRED)
    pkg_search_module(GLIB REQUIRED glib-2.0)
    target_include_directories(${PROJECT_NAME} PRIVATE ${GLIB_INCLUDE_DIRS})
    target_link_libraries(${PROJECT_NAME} INTERFACE ${GLIB_LDFLAGS})
    

    Setting a breakpoint on the last line, this is what I see in the debugger view:

    Name   Value        Type
    text1  "TEXT1\n"    char *
    text2  'T' 84 0x54  gchar
    text3  84           mytype
    

    Note that gchar is typedef char gchar; in glib/gtypes.h. However for some reason it is shown differently than my own typedef.

    My conclusion is that Qt Creator is unable to "see through" the typedef, and fails to detect:

    • That the types are actually pointer types. E.g. it should show gchar * instead of gchar.
    • That the types are actually just printable char arrays. It should show their contents, just as in the case of char *.

    I have tried a lot of permutations regarding the configuration, such as:

    • In the debugger view, trying different Display Formats for each variable and each type.
    • Enabling/Disabling Load system GDB pretty printers in the GDB options tab.
    • Enabling/Disabling Use Debugging Helper and Use code model in the Locals & Expressions options tab.
    • Repeating all previous tests with the Clang Code Model enabled/disabled.

    None of these tests changed the outcome.

    In the end, the only workaround that has worked is to create an Expression Evaluator for each variable, and apply an explicit cast to (char *). But this is clunky and very undesirable (I wouldn't want to do this for each and every variable!).

    Version information:

    • Linux Mint 18.3 Sylvia (Ubuntu 16.04 "Xenial")
    • GCC 5.4.0
    • Clang 5.0.0-3~16.04.1
    • GDB 7.11.1
    • Qt Creator 4.6.0
    1 Reply Last reply
    1
    • S Offline
      S Offline
      Sergey I.
      wrote on last edited by
      #2

      The problem is still valid with recent QtCreator 4.9.
      Does anyone have a solution? Has anyone reported this to the bug tracker?

      jsulmJ 1 Reply Last reply
      0
      • S Sergey I.

        The problem is still valid with recent QtCreator 4.9.
        Does anyone have a solution? Has anyone reported this to the bug tracker?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Sergey-I. said in Wrong char type detection in debugger:

        Has anyone reported this to the bug tracker?

        I don't know. Did you check that?

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

        1 Reply Last reply
        0

        • Login

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