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. how to programmatically break into debugger?
Forum Updated to NodeBB v4.3 + New Features

how to programmatically break into debugger?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.9k Views 2 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 12 Dec 2018, 19:18 last edited by
    #1

    on mac in xcode, one can put "Debugger()" as a statement, and when it's hit, get into the debugger (say, if an assert fires while in debug mode)
    on windows it's "DebugBreak()".

    however, when debugging using "Qt Creator" on mac, calling "Debugger()" only causes a message to be logged:

    "Debugger() was called!"
    

    in the mac gui QtCreator->Preferences->Debugger->GDB Extended, i'd'a thought there'd be a checkbox "Stop when Debugger() is called", but it ain't there.

    i see "Stop when qWarning() is called", so i check that, then in my code i do this:

    qWarning("Debugger");
    

    but that, too, merely logs something and does't pause the app and put me in the debugger.

    so... how?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      davecotter
      wrote on 31 Jan 2019, 23:11 last edited by
      #6

      @hskoglund said in how to programmatically break into debugger?:

      __debugbreak();

      YES!

      1 Reply Last reply
      0
      • H Online
        H Online
        hskoglund
        wrote on 12 Dec 2018, 20:29 last edited by
        #2

        Hi, the trick on Intel x86 processors is to inject an int 3 instruction in your code, try something like:

        __asm__("int $3\n" : : );
        
        1 Reply Last reply
        6
        • D Offline
          D Offline
          davecotter
          wrote on 12 Dec 2018, 22:47 last edited by
          #3
          __asm__("int $3\n" : : );
          

          that did it!

          1 Reply Last reply
          0
          • D Offline
            D Offline
            davecotter
            wrote on 31 Jan 2019, 20:20 last edited by
            #4

            okay this worked on mac, but it does NOT work on windows.

            On Windows in MSDEV i could have this line:

            DebugBreak();
            

            but that doesn't cause the debugger to pause the app when debugging with Qt.

            When i try to compile the above on Windows, i get this:

            0_1548966037572_Screen Shot 2019-01-31 at 12.20.26 PM.png

            1 Reply Last reply
            0
            • H Online
              H Online
              hskoglund
              wrote on 31 Jan 2019, 20:51 last edited by hskoglund
              #5

              Hi, the principle is the same (same Intel x86 processor) but a different compiler, try:

              __asm int 3;
              

              Edit: googled a bit, I see that the above is kind of old and only works when you compile for 32-bit, there's a newer alternative which also works for Arm and 64-bit builds:

              __debugbreak();
              
              1 Reply Last reply
              5
              • D Offline
                D Offline
                davecotter
                wrote on 31 Jan 2019, 23:11 last edited by
                #6

                @hskoglund said in how to programmatically break into debugger?:

                __debugbreak();

                YES!

                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