-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* machinarium: add machine_get_backtrace* This functions will fix bugs by printing backtraces Signed-off-by: rkhapov <[email protected]> * sources/console.c: clients table improvements 1) rename 'ptr' to 'id' which is more obvious 2) replace useless 'link' with 'ptr' which can be used for debugging 3) add column 'coro' with coroutine id of the client, which can be used for debugging too Signed-off-by: rkhapov <[email protected]> --------- Signed-off-by: rkhapov <[email protected]> Co-authored-by: rkhapov <[email protected]> (cherry picked from commit 81c16a5) Signed-off-by: rkhapov <[email protected]>
- Loading branch information
1 parent
fa30b51
commit d578225
Showing
4 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ set(machine_src | |
close.c | ||
connect.c | ||
bind.c | ||
backtrace.c | ||
eventfd.c | ||
cond.c | ||
read.c | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef _GNU_SOURCE | ||
#define _GNU_SOURCE | ||
#endif | ||
|
||
#include <machinarium.h> | ||
|
||
#include <stdio.h> | ||
#include <dlfcn.h> | ||
#include <execinfo.h> | ||
|
||
MACHINE_API int machine_get_backtrace(void **entries, int max) | ||
{ | ||
return backtrace(entries, max); | ||
} | ||
|
||
#define MM_BACKTRACE_STRING_N_ENTRIES 15 | ||
|
||
__thread char backtrace_string[MM_BACKTRACE_STRING_N_ENTRIES * 40]; | ||
|
||
MACHINE_API const char *machine_get_backtrace_string() | ||
{ | ||
void *bt[MM_BACKTRACE_STRING_N_ENTRIES]; | ||
int nentries = machine_get_backtrace(bt, MM_BACKTRACE_STRING_N_ENTRIES); | ||
|
||
if (nentries <= 0) { | ||
return NULL; | ||
} | ||
|
||
char *wptr = backtrace_string; | ||
for (int i = 0; i < nentries; ++i) { | ||
wptr += sprintf(wptr, "%p ", bt[i]); | ||
} | ||
|
||
wptr += sprintf(wptr, "("); | ||
|
||
for (int i = 0; i < nentries; ++i) { | ||
void *addr = bt[i]; | ||
|
||
Dl_info info; | ||
if (dladdr(addr, &info) == 0) { | ||
wptr += sprintf(wptr, "[unknown]"); | ||
} else { | ||
void *calibrated = (void *)((uintptr_t)addr - | ||
(uintptr_t)info.dli_fbase); | ||
|
||
wptr += sprintf(wptr, "%p", calibrated); | ||
} | ||
|
||
if (i != nentries - 1) { | ||
wptr += sprintf(wptr, " "); | ||
} | ||
} | ||
|
||
wptr += sprintf(wptr, ")"); | ||
*wptr = '\0'; | ||
|
||
return backtrace_string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters