pastebin - collaborative debugging tool
rovema.kpaste.net RSS

Difference between
modified post 881c3 by Anonymous on Wed 1st Sep 2021 14:15
original post e01c0dc3 by Anonymous on Wed 1st Sep 2021 13:56
Download diff
Show old version | new version | both versions

    
11
/*
2-
 * gdb_catch_c++_throw1.cpp demo
2+
 * gdb_catch_c++_throw2.cpp demo
33
 *
44
 * Use like this:
55
 * $ g++ -std=c++11 -g gdb_catch_c++_throw1.cpp
6-
 * $ printf 'catch throw\nrun\nwhere\n' | gdb --args ./a.out 2>&1 | awk '/exception thrown/,EOF { print $0 }'
6+
 *
7-
 * Catchpoint 1 (exception thrown), 0x00007ffff7e80c2e in __cxa_throw ()
7+
 *         Inferior 1 [process 21238] will be killed.
8-
 *    from /lib/x86_64-linux-gnu/libstdc++.so.6
8+
 */
9-
 * (gdb) #0  0x00007ffff7e80c2e in __cxa_throw ()
9+
#include <stdexcept>
10-
 *    from /lib/x86_64-linux-gnu/libstdc++.so.6
10+
#include <iostream>
11-
 * #1  0x00005555555552c9 in myclass::print_and_throw (this=0x7fffffffdefc)
11+
#include <stdlib.h>
12-
 *     at test1.cpp:19
12+
#include <stdio.h>
13-
 * #2  0x0000555555555262 in myclass::countdown_to_death (this=0x7fffffffdefc)
13+
#include <unistd.h>
14-
 *     at test1.cpp:14
14+
#include <execinfo.h>
15-
 * #3  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
15+
16-
 *     at test1.cpp:13
16+
class myclass
17-
 * #4  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
17+
{
18-
 *     at test1.cpp:13
18+
public:
19-
 * #5  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
19+
	int death_is_coming = 10;
20-
 *     at test1.cpp:13
20+
21-
 * #6  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
21+
	/* recursive call to make stack trace bigger */
22-
 *     at test1.cpp:13
22+
	void countdown_to_death()
23-
 * #7  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
23+
	{
24-
 *     at test1.cpp:13
24+
		if (this->death_is_coming-- > 0)
25-
 * #8  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
25+
			this->countdown_to_death();
26-
 *     at test1.cpp:13
26+
		this->print_and_throw();
27-
 * #9  0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
27+
	}
28-
 *     at test1.cpp:13
28+
	void print_and_throw()
29-
 * #10 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
29+
	{
30-
 *     at test1.cpp:13
30+
		std::cout << "#mark 1" << std::endl;
31-
 * #11 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
31+
		throw std::exception(); /* gdb should catch this */
32-
 *     at test1.cpp:13
32+
	}
33-
 * #12 0x0000555555555256 in myclass::countdown_to_death (this=0x7fffffffdefc)
33+
};
34-
 *     at test1.cpp:13
34+
35-
 * #13 0x00005555555551a7 in main (ac=1, av=0x7fffffffdff8) at test1.cpp:26
35+
/*
36-
 * (gdb) quit
36+
 * std::exception will call std::terminate() to terminate the process.
37-
 * A debugging session is active.
37+
 * NO C++ CODE is allowed at this point, use plain ISO C and ISO C
38-
 *
38+
 * I/O only!!
4039
 */
41-
#include <stdexcept>
40+
void std::terminate()
4741
{
48-
public:
42+
#define MAX_SIZE (1024)
49-
	int death_is_coming = 10;
43+
	size_t size;
44+
	void *array[MAX_SIZE];
5049
51-
	/* recursive call to make stack trace bigger */
50+
int main(int ac, char **av)
5351
	{
54-
		if (this->death_is_coming-- > 0)
52+
	myclass x;
55-
			this->countdown_to_death();
53+
	x.countdown_to_death();
56-
		this->print_and_throw();
54+
55+
	return EXIT_SUCCESS;
5756
	}
58-
	void print_and_throw()
57+
59-
	{
58+
60-
		std::cout << "#mark 1" << std::endl;
59+
61-
		throw std::exception(); /* gdb should catch this */
60+
62-
	}
61+
63-
};
62+
6463
65-
int main(int ac, char **av)
64+
66-
{
65+
67-
	myclass x;
66+
68-
	x.countdown_to_death();
67+
6968
70-
	return EXIT_SUCCESS;
69+
71-
}
70+
7271

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.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at