Stream: general

Topic: lldb for windows - jit debugging - required for wasm debug


view this post on Zulip Steve Williams (Sep 11 2021 at 15:50):

Diving in to figure out if fixed trunk or comprehend problem if still an issue.
Here's how to build lldb for Windows from llvm trunk.
pastebin.com/ZR6Z7PPB
Builds for me.

Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

view this post on Zulip Steve Williams (Sep 12 2021 at 06:51):

lldb developer has got back to us on discord.

https://discord.com/channels/636084430946959380/636732809708306432

"On Windows you build native COFF objects or ELF with MinGW? Debugging ELF via GDB JIT Interface works again with LLDB since release 12"

More details --> https://weliveindetail.github.io/blog/post/2021/04/19/lldb-12-jit-interface.html

Can anyone answer his question, plz. I don't understand what's going on here at all yet.

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
A regression that reached back to version 6 was fixed in the latest release.

view this post on Zulip Steve Williams (Sep 12 2021 at 10:20):

Debugging ELF via GDB JIT Interface works again with LLDB since release 12

wasmtime generates COFF or ELF debug object please.

view this post on Zulip Steve Williams (Sep 12 2021 at 10:23):

here's apparently what's going on : https://alexene.dev/2020/09/04/webassembly-without-the-browser-part-2.html

view this post on Zulip Steve Williams (Sep 12 2021 at 12:02):

issue presented as suspected lldb (windows) bug, here : https://discord.com/channels/636084430946959380/636732809708306432

Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.

view this post on Zulip Steve Williams (Sep 13 2021 at 13:00):

https://bugs.llvm.org/show_bug.cgi?id=51832

view this post on Zulip Steve Williams (Sep 18 2021 at 14:06):

got lldb running under visual studio debugger. issue appears to be inability to resolve __jit_debug_register_code function.

on windows, to expose functions for external access, function must be declared

where defined : extern "C" __declspec(dllexport)
where accessed (statically) : extern "C" __declspec(dllimport)

suspect wasmtime runtime and/or lldb not doing this.

trying to locate where wasmtime accesses or defines this function.

search thru entire wasmtime repo didn't find jit_debug_register_code

unclear how the gdb jit interface binds. clues welcome.

view this post on Zulip bjorn3 (Sep 18 2021 at 14:10):

I think that can be added here: https://github.com/bytecodealliance/wasmtime/blob/4376cf2609df7abe48174aade0907b90f3f2b58a/crates/runtime/src/helpers.c#L46

Standalone JIT-style runtime for WebAssembly, using Cranelift - wasmtime/helpers.c at 4376cf2609df7abe48174aade0907b90f3f2b58a · bytecodealliance/wasmtime

view this post on Zulip Steve Williams (Sep 18 2021 at 14:15):

thanks bjorn3 :) so ... that's not declared __declspec(dllexport) so lldb can't find it ... so appears the bug. or at least one of them.
also the asm isn't defined so function might be optimized out. so bug at this point looks to be wasmtime, not lldb.

view this post on Zulip Steve Williams (Sep 18 2021 at 14:52):

a little further :)

https://pastebin.com/u8Eptv6h

Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

view this post on Zulip Steve Williams (Sep 18 2021 at 15:08):

weird. have that marked export too.

https://pastebin.com/dknDqn9z

why isn't that found ?

Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

view this post on Zulip Steve Williams (Sep 18 2021 at 15:08):

ADV_SW_PATCH in above to locate 2 tiny changes.

view this post on Zulip Steve Williams (Sep 18 2021 at 15:16):

never tried exporting data before, only functions so maybe have the syntax wrong.

view this post on Zulip Steve Williams (Sep 18 2021 at 15:26):

now.png

view this post on Zulip Steve Williams (Sep 18 2021 at 15:46):

next issue appears to be lldb insisting on binding debug descriptor as data & windows perhaps not giving it that much info. so a tweak on lldb side.

view this post on Zulip Steve Williams (Sep 18 2021 at 15:48):

https://lldb.llvm.org/cpp_reference/JITLoaderGDB_8cpp_source.html
line 201 - going to change that to Any & see if it binds.

view this post on Zulip Steve Williams (Sep 18 2021 at 16:00):

& that's it :) tiny fix in wasmtime, tiny one in lldb :)

view this post on Zulip Steve Williams (Sep 18 2021 at 16:03):

now.png

view this post on Zulip Steve Williams (Sep 18 2021 at 16:05):

LLDB fix : llvm-project\lldb\source\Plugins\JITLoader\GDB\JITLoaderGDB.cpp

module_list, ConstString("__jit_debug_descriptor"), eSymbolTypeAny); //eSymbolTypeData);

needs tidying so it can ensure qualified search where platform allows it, but that's essentially it.

if anyone knows how to query whether a symbol is data or function on windows, happy to take it all the way.

view this post on Zulip Steve Williams (Sep 18 2021 at 16:20):

so ... 2 tiny changes that affect windows only build in 1 file required to resolve. both in here marked ADV_SW_PATCH

file: wasmtime/crates/runtime/src/helpers.c
https://pastebin.com/dknDqn9z

how should I submit the patch - via git ?

Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

view this post on Zulip Steve Williams (Sep 18 2021 at 16:33):

lldb change so you can verify & access early if you'd like, as follows :

file: llvm-project\lldb\source\Plugins\JITLoader\GDB\JITLoaderGDB.cpp

m_jit_descriptor_addr = GetSymbolAddress(
module_list, ConstString("__jit_debug_descriptor"),
#ifdef _MSC_VER
// Windows implementation not indicating symbol is Data so we use Any as workaround for the time being.
eSymbolTypeAny);
#else
eSymbolTypeData);
#endif

view this post on Zulip Steve Williams (Sep 18 2021 at 16:44):

if anyone with rights wants to just drop that in, please just do it. chances of it breaking anything that was working previously is very remote.

view this post on Zulip Steve Williams (Sep 18 2021 at 16:46):

or happy to submit formally when I can figure out how.

view this post on Zulip Steve Williams (Sep 20 2021 at 13:55):

sorry, I'm stupid - how do I submit a patch please. tried git push but insufficient access.

view this post on Zulip Steve Williams (Sep 20 2021 at 13:57):

ahhh - we're doing this as git issues ?

view this post on Zulip Steve Williams (Sep 20 2021 at 14:01):

wasmtime_windows_export_jit.diff

view this post on Zulip bjorn3 (Sep 20 2021 at 14:19):

On github the normal way to submit a patch would be to push the commit to your fork of the target repo and then open a pull request.

view this post on Zulip Steve Williams (Sep 20 2021 at 14:55):

thanks, bjorn3 :) lets see if I can fail my way through that :)

lldb issue in process here if that interests anybody : https://reviews.llvm.org/D110066

view this post on Zulip Steve Williams (Sep 27 2021 at 18:24):

forked this & took it forward. might interest you guys too.

https://github.com/adv-sw/lldbg

A lightweight native GUI for LLDB. Contribute to adv-sw/lldbg development by creating an account on GitHub.

view this post on Zulip Scott Waye (Sep 27 2021 at 21:04):

That looks nice. It uses DWARF?

view this post on Zulip Steve Williams (Sep 28 2021 at 09:39):

ELF afaik - whatever wasmtime emits via GDB/JIT interface, but aside from a few custom tweaks, its basically lldb front end, so anything lldb can debug.

still early, stlll bits that need fixing up, but its basically sound now. thanks.

view this post on Zulip Steve Williams (Sep 28 2021 at 11:24):

just fixed breakpoint toggle.


Last updated: Oct 23 2024 at 20:03 UTC