-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lldb] Implement WebAssembly debugging #77949
Open
paolosevMSFT
wants to merge
9
commits into
llvm:main
Choose a base branch
from
paolosevMSFT:WebAssembly24
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
30d932b
Add support for source-level debugging of WebAssembly code
paolosevMSFT cbd0466
Add unit tests
paolosevMSFT db0bc48
Add test files and fix formatting
paolosevMSFT f1232b8
Merge branch 'main' into WebAssembly24
paolosevMSFT 18f853c
Address review comments
paolosevMSFT 89c4ec1
Fix formatting
paolosevMSFT 67c293c
Merge branch 'main' into WebAssembly24
paolosevMSFT 0ca8b8b
Address more review comments
paolosevMSFT 13bb861
Fix formatting
paolosevMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -346,6 +346,16 @@ static offset_t GetOpcodeDataSize(const DataExtractor &data, | |
return (offset - data_offset) + subexpr_len; | ||
} | ||
|
||
case DW_OP_WASM_location: { | ||
uint8_t wasm_op = data.GetU8(&offset); | ||
if (wasm_op == 3) { | ||
data.GetU32(&offset); | ||
} else { | ||
data.GetULEB128(&offset); | ||
} | ||
paolosevMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return offset - data_offset; | ||
} | ||
|
||
default: | ||
if (!dwarf_cu) { | ||
return LLDB_INVALID_OFFSET; | ||
|
@@ -2595,6 +2605,37 @@ bool DWARFExpression::Evaluate( | |
break; | ||
} | ||
|
||
case DW_OP_WASM_location: { | ||
uint8_t wasm_op = opcodes.GetU8(&offset); | ||
uint32_t index; | ||
|
||
/* LLDB doesn't have an address space to represents WebAssembly locals, | ||
* globals and operand stacks. | ||
* We encode these elements into virtual registers: | ||
* | tag: 2 bits | index: 30 bits | | ||
* where tag is: | ||
* 0: Not a WebAssembly location | ||
* 1: Local | ||
* 2: Global | ||
* 3: Operand stack value | ||
paolosevMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
if (wasm_op == 3) { | ||
paolosevMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
index = opcodes.GetU32(&offset); | ||
wasm_op = 2; // Global | ||
paolosevMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
index = opcodes.GetULEB128(&offset); | ||
} | ||
|
||
reg_num = (((wasm_op + 1) & 0x03) << 30) | (index & 0x3fffffff); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we adding 1 to the wasm_op? Can't we just set it correctly above? Also it would be nice to have an enum or constant for |
||
|
||
if (ReadRegisterValueAsScalar(reg_ctx, reg_kind, reg_num, error_ptr, tmp)) | ||
stack.push_back(tmp); | ||
else | ||
return false; | ||
|
||
break; | ||
} | ||
|
||
default: | ||
if (dwarf_cu) { | ||
if (dwarf_cu->GetSymbolFileDWARF().ParseVendorDWARFOpcode( | ||
|
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
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
add_lldb_library(lldbPluginProcessWasm PLUGIN | ||
ProcessWasm.cpp | ||
ThreadWasm.cpp | ||
UnwindWasm.cpp | ||
wasmRegisterContext.cpp | ||
|
||
LINK_LIBS | ||
lldbCore | ||
${LLDB_PLUGINS} | ||
LINK_COMPONENTS | ||
Support | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above we have FixCodeAddres() and FixDataAddress(). Will this function fix any kind of address, or just a code address? If it is just code, then maybe we can just modify the above
FixCodeAddress(...)
and add the StackFrame to that API which can default to nullptr.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought to add a new function because
Process::FixCodeAddress
,Process::FixDataAddress
,Process::FixAnyAddress
by default forward the call toABI::FixCodeAddress
,ABI::FixDataAddress
,ABI::FixAnyAddress
, which are implemented by plugin-specific ABIs likeABISysV_arm
,ABIMacOSX_arm
. But here we are not really dealing with a different ABI, it is more a custom representation of Wasm memory addresses used between the debugger and the Wasm engine.If you prefer, we could reuse
Process::FixAnyAddress
, making it virtual and overriding it inProcessWasm
.