Skip to content

Commit

Permalink
implement __set_backtrace_on_abort and define more operators for pthr…
Browse files Browse the repository at this point in the history
…ead_t (#57)

* src: implement __set_backtrace_on_abort(true|false)

This is to avoid zoslib's abort() from calling
__display_backtrace() if the current process already
had function in place that does that (so avoid a
duplicate backtrace from being output).

* include: define operators for pthread_t ==|!= int
  • Loading branch information
gabylb authored and zsw007 committed Jan 18, 2022
1 parent c50d63a commit a540a28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/zos-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ int gettid();
*/
void __display_backtrace(int fd);

/**
* Enable or disable abort() from calling display_backtrace(). Default is true.
*/
void __set_backtrace_on_abort(bool flag);

/**
* Execute a file.
* \param [in] name used to construct a pathname that identifies the new
Expand Down Expand Up @@ -578,6 +583,12 @@ inline bool operator<(const pthread_t &_a, const pthread_t &_b) {
inline bool operator>(const pthread_t &_a, const pthread_t &_b) {
return _a.__ > _b.__;
}
inline bool operator==(const pthread_t &_a, const int _b) {
return _a.__ == static_cast<unsigned long long>(_b);
}
inline bool operator!=(const pthread_t &_a, const int _b) {
return _a.__ != static_cast<unsigned long long>(_b);
}

struct zoslibEnvar {
std::string envarName;
Expand Down
9 changes: 8 additions & 1 deletion src/zos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static char **__argv = nullptr;
static int __argc = -1;
static pthread_t _timer_tid;
static int *__main_thread_stack_top_address = 0;
static bool __is_backtrace_on_abort = true;

#if defined(BUILD_VERSION)
const char *__zoslib_version = BUILD_VERSION;
Expand Down Expand Up @@ -659,11 +660,17 @@ extern "C" void *__dlcb_entry_addr(void *dlcb) {
}

extern "C" void abort(void) {
__display_backtrace(STDERR_FILENO);
if (__is_backtrace_on_abort) {
__display_backtrace(STDERR_FILENO);
}
__zinit::getInstance()->__abort();
exit(-1); // never reach here, suppress clang warning
}

extern "C" void __set_backtrace_on_abort(bool flag) {
__is_backtrace_on_abort = flag;
}

int __cond_timed_wait(unsigned int secs, unsigned int nsecs,
unsigned int event_list, unsigned int *secs_rem,
unsigned int *nsecs_rem) {
Expand Down

0 comments on commit a540a28

Please sign in to comment.