- /*
- * gdb_catch_c++_throw1.cpp demo
- *
- * Use like this:
- * $ g++ -std=c++11 -g gdb_catch_c++_throw1.cpp
- * $ printf 'catch throw\nrun\nwhere\n' | gdb --args ./a.out 2>&1 | awk '/exception thrown/,EOF { print $0 }'
- * Catchpoint 1 (exception thrown), 0x00007ffff7e80c2e in __cxa_throw ()
- * from /lib/x86_64-linux-gnu/libstdc++.so.6
- * (gdb) #0 0x00007ffff7e80c2e in __cxa_throw ()
- * from /lib/x86_64-linux-gnu/libstdc++.so.6
- * #1 0x00005555555552c9 in myclass::print_and_throw (this=0x7fffffffdefc)
- * at test1.cpp:19
- * #2 0x0000555555555262 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:14
- * #3 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #4 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #5 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #6 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #7 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #8 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #9 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #10 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #11 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #12 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
- * at test1.cpp:13
- * #13 0x00005555555551a7 in main (ac=1, av=0x7fffffffdff8) at test1.cpp:26
- * (gdb) quit
- * A debugging session is active.
- *
- * Inferior 1 [process 21238] will be killed.
- */
- #include <stdexcept>
- #include <iostream>
- #include <stdlib.h>
- #include <stdio.h>
- class myclass
- {
- public:
- int death_is_coming = 10;
- /* recursive call to make stack trace bigger */
- void countdown_to_death()
- {
- if (this->death_is_coming-- > 0)
- this->countdown_to_death();
- this->print_and_throw();
- }
- void print_and_throw()
- {
- std::cout << "#mark 1" << std::endl;
- throw std::exception(); /* gdb should catch this */
- }
- };
- int main(int ac, char **av)
- {
- myclass x;
- x.countdown_to_death();
- return EXIT_SUCCESS;
- }
gdb_catch_c++_throw1.cpp
Posted by Anonymous on Wed 1st Sep 2021 13:56
raw | new post
view followups (newest first): gdb_catch_c++_throw2.cpp by Anonymous
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.