2 * Debug information support.
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "qemu/osdep.h"
8 #include "qemu/lockable.h"
9 #include "tcg/debuginfo.h"
11 #include <elfutils/libdwfl.h>
13 static QemuMutex lock
;
15 static const Dwfl_Callbacks dwfl_callbacks
= {
17 .find_debuginfo
= dwfl_standard_find_debuginfo
,
18 .section_address
= NULL
,
19 .debuginfo_path
= NULL
,
22 __attribute__((constructor
))
23 static void debuginfo_init(void)
25 qemu_mutex_init(&lock
);
28 void debuginfo_report_elf(const char *name
, int fd
, uint64_t bias
)
30 QEMU_LOCK_GUARD(&lock
);
33 dwfl_report_begin_add(dwfl
);
35 dwfl
= dwfl_begin(&dwfl_callbacks
);
39 dwfl_report_elf(dwfl
, name
, name
, fd
, bias
, true);
40 dwfl_report_end(dwfl
, NULL
, NULL
);
44 void debuginfo_lock(void)
46 qemu_mutex_lock(&lock
);
49 void debuginfo_query(struct debuginfo_query
*q
, size_t n
)
51 const char *symbol
, *file
;
52 Dwfl_Module
*dwfl_module
;
63 for (i
= 0; i
< n
; i
++) {
64 dwfl_module
= dwfl_addrmodule(dwfl
, q
[i
].address
);
69 if (q
[i
].flags
& DEBUGINFO_SYMBOL
) {
70 symbol
= dwfl_module_addrinfo(dwfl_module
, q
[i
].address
,
71 &dwfl_offset
, &dwfl_sym
,
75 q
[i
].offset
= dwfl_offset
;
79 if (q
[i
].flags
& DEBUGINFO_LINE
) {
80 dwfl_line
= dwfl_module_getsrc(dwfl_module
, q
[i
].address
);
82 file
= dwfl_lineinfo(dwfl_line
, NULL
, &line
, 0, NULL
, NULL
);
92 void debuginfo_unlock(void)
94 qemu_mutex_unlock(&lock
);