pastebin - collaborative debugging tool
rovema.kpaste.net RSS

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

    
11
/*
22
 * gdb_catch_c++_throw2.cpp demo
33
 *
44
 * Use like this:
55
 * $ g++ -std=c++11 -g gdb_catch_c++_throw1.cpp
66
 *
7-
 *         Inferior 1 [process 21238] will be killed.
87
 */
98
#include <stdexcept>
109
#include <iostream>
1110
#include <stdlib.h>
1211
#include <stdio.h>
1312
#include <unistd.h>
1413
#include <execinfo.h>
1514
1615
class myclass
1716
{
1817
public:
1918
	int death_is_coming = 10;
2019
2120
	/* recursive call to make stack trace bigger */
2221
	void countdown_to_death()
2322
	{
2423
		if (this->death_is_coming-- > 0)
2524
			this->countdown_to_death();
2625
		this->print_and_throw();
2726
	}
2827
	void print_and_throw()
2928
	{
3029
		std::cout << "#mark 1" << std::endl;
3130
		throw std::exception(); /* gdb should catch this */
3231
	}
3332
};
3433
3534
/*
3635
 * std::exception will call std::terminate() to terminate the process.
3736
 * NO C++ CODE is allowed at this point, use plain ISO C and ISO C
3837
 * I/O only!!
3938
 */
4039
void std::terminate()
4140
{
4241
#define MAX_SIZE (1024)
4342
	size_t size;
4443
	void *array[MAX_SIZE];
4544
	size = backtrace(array, MAX_SIZE);
4645
	backtrace_symbols_fd(array, size, STDERR_FILENO);
4746
	exit(EXIT_FAILURE);
4847
}
4948
5049
int main(int ac, char **av)
5150
{
5251
	myclass x;
5352
	x.countdown_to_death();
5453
5554
	return EXIT_SUCCESS;
5655
}
5756

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