This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit c77a628 committed Oct 16, 2024 · 1 / 1
1 parent b648e64 commit c77a628 Copy full SHA for c77a628
File tree 2 files changed +45
-0
lines changed
2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,9 @@ QEMU_EXTERN_C int daemon(int, int);
133
133
#include <setjmp.h>
134
134
#include <signal.h>
135
135
136
+ #define UNW_LOCAL_ONLY
137
+ #include <libunwind.h>
138
+
136
139
#ifdef CONFIG_IOVEC
137
140
#include <sys/uio.h>
138
141
#endif
@@ -812,6 +815,44 @@ static inline void qemu_thread_jit_write(void) {}
812
815
static inline void qemu_thread_jit_execute (void ) {}
813
816
#endif
814
817
818
+ /* returns caller, return 0 if it worked */
819
+ static inline __attribute__((always_inline ))
820
+ int unwind_caller (GString * res )
821
+ {
822
+ unw_cursor_t cursor ;
823
+ unw_context_t context ;
824
+
825
+ unw_getcontext (& context );
826
+ unw_init_local (& cursor , & context );
827
+
828
+ bool unwind_success = unw_step (& cursor );
829
+ if (!unwind_success ) {
830
+ g_string_printf (res , "<unknown - can't unwind>" );
831
+ return -1 ;
832
+ }
833
+
834
+ unw_word_t offset ;
835
+ char sym [256 ];
836
+ if (unw_get_proc_name (& cursor , sym , sizeof (sym ), & offset ) != 0 ) {
837
+ g_string_printf (res , "<unknown - can't get proc info>" );
838
+ return -2 ;
839
+ }
840
+
841
+ g_string_printf (res , "%s+0x%" PRIx64 , sym , offset );
842
+ return 0 ;
843
+ }
844
+
845
+ static inline __attribute__((always_inline ))
846
+ const char * qemu_get_caller (void )
847
+ {
848
+ static __thread GString * info ;
849
+ if (!info ) {
850
+ info = g_string_new (0 );
851
+ }
852
+ unwind_caller (info );
853
+ return info -> str ;
854
+ }
855
+
815
856
/**
816
857
* Platforms which do not support system() return ENOSYS
817
858
*/
Original file line number Diff line number Diff line change @@ -954,6 +954,9 @@ have_xen_pci_passthrough = get_option('xen_pci_passthrough') \
954
954
# Dependencies #
955
955
################
956
956
957
+ libunwind = dependency (' libunwind' , required : true , method : ' pkg-config' )
958
+ add_project_dependencies(libunwind, language : all_languages)
959
+
957
960
# When bumping glib minimum version, please check also whether to increase
958
961
# the _WIN32_WINNT setting in osdep.h according to the value from glib.
959
962
# You should also check if any of the glib.version() checks
@@ -3577,6 +3580,7 @@ event_loop_base = declare_dependency(objects: event_loop_base.extract_all_object
3577
3580
stub_ss = stub_ss.apply({})
3578
3581
3579
3582
util_ss.add_all(trace_ss)
3583
+ util_ss.add(libunwind)
3580
3584
util_ss = util_ss.apply({})
3581
3585
libqemuutil = static_library (' qemuutil' ,
3582
3586
build_by_default : false ,
You can’t perform that action at this time.
0 commit comments