Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Another long shot...

Another long shot...

Scheduled Pinned Locked Moved C / C++ / MFC
debugginghelpc++tutoriallounge
3 Posts 2 Posters 1 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I need some general /generic advise how to tackle this problem. It is in my C++ QT code and I cannot even start to debug at the beginning of the code. I have a "main" wrapper app / project and bunch of subprojects. I used to be able to set breakpoint at the start of the main project - not anymore. I have no clue from where this error comes from and how it started on perfectly working code. . I can disable all subprojects and still get this error.

    terminate called after throwing an instance of 'std::bad_alloc'
    what(): std::bad_alloc

    I am not asking for code, just some advise how to tackle this error.

    K 1 Reply Last reply
    0
    • L Lost User

      I need some general /generic advise how to tackle this problem. It is in my C++ QT code and I cannot even start to debug at the beginning of the code. I have a "main" wrapper app / project and bunch of subprojects. I used to be able to set breakpoint at the start of the main project - not anymore. I have no clue from where this error comes from and how it started on perfectly working code. . I can disable all subprojects and still get this error.

      terminate called after throwing an instance of 'std::bad_alloc'
      what(): std::bad_alloc

      I am not asking for code, just some advise how to tackle this error.

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      First, make sure you're creating a debug build. Whatever IDE you're using should have a Build or Compile config section, so take a look and make sure that's set. Your IDE should have a built in link to the debugger, so just run the program in the debugger. When the error is thrown, the debugger should stop the program and allow you to examine the state of the program. If you need to use the command line, here's an example to help you get started:

      $ cat bad_alloc.cpp
      #include <iostream>

      int main()
      {
      size_t lim = 2;
      while(true)
      {
      int *arr = new int[lim];
      delete[] arr;
      lim *= 2;
      }
      return 0;
      }
      $ # That will eventually try to allocate too much memory
      $ # compile with gdb, in 32 bit mode to get a quick crash
      $ g++ -m32 -ggdb bad_alloc.cpp -o bad_alloc
      $ # debug the program
      $ gdb bad_alloc

      GDB startup messages snipped out

      Reading symbols from bad_alloc...
      (gdb) run
      Starting program: /home/ebacon/tmp/c++/bad_alloc
      terminate called after throwing an instance of 'std::bad_array_new_length'
      what(): std::bad_array_new_length

      Program received signal SIGABRT, Aborted.
      0xf7fce559 in __kernel_vsyscall ()
      Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-10.fc33.i686 libgcc-10.3.1-1.fc33.i686
      (gdb) # take a look at the backtrace
      (gdb) bt
      #0 0xf7fce559 in __kernel_vsyscall ()
      #1 0xf7d2759a in raise () from /lib/libc.so.6
      #2 0xf7d0f3d0 in abort () from /lib/libc.so.6
      #3 0x0804c829 in __gnu_cxx::__verbose_terminate_handler() [clone .cold] ()
      #4 0x080dee78 in __cxxabiv1::__terminate(void (*)()) ()
      #5 0x080def01 in std::terminate() ()
      #6 0x0804dbb0 in __cxa_throw ()
      #7 0x0804a7ee in __cxa_throw_bad_array_new_length ()
      #8 0x0804d9f7 in main () at bad_alloc.cpp:8
      (gdb) # all the frames except the last are part of the STL,
      (gdb) # so we're probably only interested in frame 8
      (gdb) frame 8
      #8 0x0804d9f7 in main () at bad_alloc.cpp:8
      8 int *arr = new int[lim];
      (gdb) # The 8 in the line above refers to line 8 of the source
      (gdb) # print the value of lim
      (gdb) p lim
      $1 = 536870912
      (gdb) quit
      A debugging session is active.
      Inferior 1 [process 3076940] will be killed.
      Quit anyway? (y or n) y
      $

      Hopefully, that's enough to get you started. If you need more, then Google is your friend.

      Keep Calm and C

      L 1 Reply Last reply
      0
      • K k5054

        First, make sure you're creating a debug build. Whatever IDE you're using should have a Build or Compile config section, so take a look and make sure that's set. Your IDE should have a built in link to the debugger, so just run the program in the debugger. When the error is thrown, the debugger should stop the program and allow you to examine the state of the program. If you need to use the command line, here's an example to help you get started:

        $ cat bad_alloc.cpp
        #include <iostream>

        int main()
        {
        size_t lim = 2;
        while(true)
        {
        int *arr = new int[lim];
        delete[] arr;
        lim *= 2;
        }
        return 0;
        }
        $ # That will eventually try to allocate too much memory
        $ # compile with gdb, in 32 bit mode to get a quick crash
        $ g++ -m32 -ggdb bad_alloc.cpp -o bad_alloc
        $ # debug the program
        $ gdb bad_alloc

        GDB startup messages snipped out

        Reading symbols from bad_alloc...
        (gdb) run
        Starting program: /home/ebacon/tmp/c++/bad_alloc
        terminate called after throwing an instance of 'std::bad_array_new_length'
        what(): std::bad_array_new_length

        Program received signal SIGABRT, Aborted.
        0xf7fce559 in __kernel_vsyscall ()
        Missing separate debuginfos, use: dnf debuginfo-install glibc-2.32-10.fc33.i686 libgcc-10.3.1-1.fc33.i686
        (gdb) # take a look at the backtrace
        (gdb) bt
        #0 0xf7fce559 in __kernel_vsyscall ()
        #1 0xf7d2759a in raise () from /lib/libc.so.6
        #2 0xf7d0f3d0 in abort () from /lib/libc.so.6
        #3 0x0804c829 in __gnu_cxx::__verbose_terminate_handler() [clone .cold] ()
        #4 0x080dee78 in __cxxabiv1::__terminate(void (*)()) ()
        #5 0x080def01 in std::terminate() ()
        #6 0x0804dbb0 in __cxa_throw ()
        #7 0x0804a7ee in __cxa_throw_bad_array_new_length ()
        #8 0x0804d9f7 in main () at bad_alloc.cpp:8
        (gdb) # all the frames except the last are part of the STL,
        (gdb) # so we're probably only interested in frame 8
        (gdb) frame 8
        #8 0x0804d9f7 in main () at bad_alloc.cpp:8
        8 int *arr = new int[lim];
        (gdb) # The 8 in the line above refers to line 8 of the source
        (gdb) # print the value of lim
        (gdb) p lim
        $1 = 536870912
        (gdb) quit
        A debugging session is active.
        Inferior 1 [process 3076940] will be killed.
        Quit anyway? (y or n) y
        $

        Hopefully, that's enough to get you started. If you need more, then Google is your friend.

        Keep Calm and C

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thanks very much. Since my program is "under construction" it always runs in debug mode. The error I am getting does not even get me to the first line of code to set brake point. Since last major change I did was to change the entire project from QT version 5.12.12 to 6.2.2. - that is the prime suspect. Since then I found out that I can "configure" individual project to specific version.... In theory - first project I tried it did not work... I appreciate your post, but since my backup works I will try to find out why the "disable versions prior to xyz " does not work first. I need only one of the subprojects to be of latest QT version. Cheers

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups