|
15 | 15 | #include "compat.h" |
16 | 16 |
|
17 | 17 | #ifdef VMP_SUPPORTS_NATIVE_PROFILING |
18 | | -#include "unwind/vmprof_unwind.h" |
19 | 18 |
|
| 19 | +#ifdef VMPROF_LINUX |
| 20 | +#include "unwind/vmprof_unwind.h" |
20 | 21 | typedef mcontext_t unw_context_t; |
21 | 22 |
|
22 | 23 | // functions copied from libunwind using dlopen |
23 | | - |
24 | 24 | static int (*unw_get_reg)(unw_cursor_t*, int, unw_word_t*) = NULL; |
25 | 25 | static int (*unw_step)(unw_cursor_t*) = NULL; |
26 | 26 | static int (*unw_init_local)(unw_cursor_t *, unw_context_t *) = NULL; |
27 | 27 | static int (*unw_get_proc_info)(unw_cursor_t *, unw_proc_info_t *) = NULL; |
28 | 28 | static int (*unw_get_proc_name)(unw_cursor_t *, char *, size_t, unw_word_t*) = NULL; |
29 | 29 | static int (*unw_is_signal_frame)(unw_cursor_t *) = NULL; |
30 | 30 | static int (*unw_getcontext)(unw_context_t *) = NULL; |
| 31 | +#else |
| 32 | +#include <libunwind.h> |
| 33 | +#endif |
31 | 34 |
|
32 | 35 | #endif |
33 | 36 |
|
@@ -508,53 +511,50 @@ static void * libhandle = NULL; |
508 | 511 | #endif |
509 | 512 | #define U_PREFIX "_U" |
510 | 513 | #define UL_PREFIX "_UL" |
511 | | -#else |
512 | | -#define LIBUNWIND "/usr/lib/system/libunwind.dylib" |
513 | | -#define PREFIX "unw" |
514 | | -#define U_PREFIX "" |
515 | | -#define UL_PREFIX "" |
516 | 514 | #endif |
517 | 515 |
|
518 | 516 | int vmp_native_enable(void) { |
519 | | - vmp_native_traces_enabled = 1; |
520 | | - |
| 517 | +#ifdef VMPROF_LINUX |
521 | 518 | if (!unw_get_reg) { |
522 | | - if (!(libhandle = dlopen(LIBUNWIND, RTLD_LAZY | RTLD_LOCAL))) { |
| 519 | + if ((libhandle = dlopen(LIBUNWIND, RTLD_LAZY | RTLD_LOCAL)) == NULL) { |
523 | 520 | goto bail_out; |
524 | 521 | } |
525 | | - if (!(unw_get_reg = dlsym(libhandle, UL_PREFIX PREFIX "_get_reg"))) { |
| 522 | + if ((unw_get_reg = dlsym(libhandle, UL_PREFIX PREFIX "_get_reg")) == NULL) { |
526 | 523 | goto bail_out; |
527 | 524 | } |
528 | | - if (!(unw_get_proc_info = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_info"))){ |
| 525 | + if ((unw_get_proc_info = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_info")) == NULL){ |
529 | 526 | goto bail_out; |
530 | 527 | } |
531 | | - if (!(unw_get_proc_name = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_name"))){ |
| 528 | + if ((unw_get_proc_name = dlsym(libhandle, UL_PREFIX PREFIX "_get_proc_name")) == NULL){ |
532 | 529 | goto bail_out; |
533 | 530 | } |
534 | | - if (!(unw_init_local = dlsym(libhandle, UL_PREFIX PREFIX "_init_local"))) { |
| 531 | + if ((unw_init_local = dlsym(libhandle, UL_PREFIX PREFIX "_init_local")) == NULL) { |
535 | 532 | goto bail_out; |
536 | 533 | } |
537 | | - if (!(unw_step = dlsym(libhandle, UL_PREFIX PREFIX "_step"))) { |
| 534 | + if ((unw_step = dlsym(libhandle, UL_PREFIX PREFIX "_step")) == NULL) { |
538 | 535 | goto bail_out; |
539 | 536 | } |
540 | | - if (!(unw_is_signal_frame = dlsym(libhandle, UL_PREFIX PREFIX "_is_signal_frame"))) { |
| 537 | + if ((unw_is_signal_frame = dlsym(libhandle, UL_PREFIX PREFIX "_is_signal_frame")) == NULL) { |
541 | 538 | goto bail_out; |
542 | 539 | } |
543 | | - if (!(unw_getcontext = dlsym(libhandle, U_PREFIX PREFIX "_getcontext"))) { |
| 540 | + if ((unw_getcontext = dlsym(libhandle, U_PREFIX PREFIX "_getcontext")) == NULL) { |
544 | 541 | goto bail_out; |
545 | 542 | } |
546 | 543 | } |
| 544 | +#endif |
| 545 | + |
| 546 | + vmp_native_traces_enabled = 1; |
547 | 547 |
|
548 | | -#if defined(__unix__) |
| 548 | +#ifdef VMPROF_LINUX |
549 | 549 | return vmp_read_vmaps("/proc/self/maps"); |
550 | | -#elif defined(__APPLE__) |
551 | | - return vmp_read_vmaps(NULL); |
552 | | -#endif |
553 | 550 | bail_out: |
554 | 551 | vmprof_error = dlerror(); |
555 | 552 | fprintf(stderr, "could not load libunwind at runtime. error: %s\n", vmprof_error); |
556 | 553 | vmp_native_traces_enabled = 0; |
557 | 554 | return 0; |
| 555 | +#else |
| 556 | + return vmp_read_vmaps(NULL); |
| 557 | +#endif |
558 | 558 | } |
559 | 559 |
|
560 | 560 | void vmp_native_disable(void) { |
|
0 commit comments