Skip to content

Commit

Permalink
SWPTP-1532: add programmatic backtrace on dead thread access
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Oct 23, 2024
1 parent afaba12 commit 546848c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ STATIC_LIBRARIES :=
TARGETS :=
MKDIR = mkdir -p

ifdef DEBUG
# Enable symbolic backtraces
LDFLAGS += -rdynamic
endif

# Build directory
BUILD_DIR = build

Expand Down
4 changes: 4 additions & 0 deletions src/include/sfptpd_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,8 @@ int sfptpd_ht_get_num_entries(struct sfptpd_hash_table *table);
*/
int sfptpd_find_running_programs(struct sfptpd_prog *others);

/** Log a backtrace of the current thread.
*/
void sfptpd_debug_backtrace(void);

#endif /* _SFPTPD_MISC_H */
24 changes: 24 additions & 0 deletions src/sfptpd_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <fts.h>
#include <fnmatch.h>
#include <linux/taskstats.h>
#include <execinfo.h>

#include "sfptpd_misc.h"
#include "sfptpd_logging.h"
Expand Down Expand Up @@ -191,6 +192,29 @@ void sfptpd_local_strftime(char *s, size_t max, const char *format, const sfptpd
}


void sfptpd_debug_backtrace(void)
{
#define BACKTRACE_SIZE 128
void **buffer = malloc(BACKTRACE_SIZE * sizeof(void *));
char **strings;
int len;

if (!buffer)
return;

len = backtrace(buffer, BACKTRACE_SIZE);
strings = backtrace_symbols(buffer, len);
if (strings) {
while(--len >= 1) {
TRACE_L3("frame %d: %s\n", len, strings[len]);
}
free(strings);
}

free(buffer);
}


/****************************************************************************
* Hash table functions
****************************************************************************/
Expand Down
5 changes: 4 additions & 1 deletion src/sfptpd_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ int sfptpd_msg_send_wait(sfptpd_msg_hdr_t *msg,

rc = queue_send(&recipient->queue_general, msg);

SFPTPD_MSG_TRACE("msg %p send %d reply %d wait rc %d 0x%x\n", msg,
SFPTPD_MSG_TRACE("msg %p send %d reply %d wait rc %d id 0x%x\n", msg,
recipient->queue_general.pipe.fds[PIPE_WRITE_IDX],
reply_fd, rc, id);

Expand Down Expand Up @@ -1996,6 +1996,9 @@ struct sfptpd_thread *sfptpd_thread_self(void)
{
struct sfptpd_thread *self = thread_self();

if (self == NULL)
sfptpd_debug_backtrace();

assert(self != NULL);
return self;
}
Expand Down

0 comments on commit 546848c

Please sign in to comment.