Add lldb-repr command for tests/debuginfo#158298
Conversation
b24c4d8 to
ef79d4f
Compare
e416d4e to
7f7680a
Compare
| if target_name.ends_with("windows-msvc") { | ||
| "windows_msvc" | ||
| } else if target_name.ends_with("windows-gnu") || target_name.ends_with("windows-gnullvm") { | ||
| "windows-gnu" |
There was a problem hiding this comment.
The dash is a bit inconsistent here, as there are underscores in the other two names.
| expected = INPUT_DATA.breakpoints[breakpoint_idx][var_name] | ||
|
|
||
| var_ok = var_matches(var, expected, valobj) | ||
| if len(VARS_TESTED) <= breakpoint_idx: |
There was a problem hiding this comment.
This looks a bit sus, is there some guarantee that the check function will be called with increasing values of breakpoint_idx?
There was a problem hiding this comment.
The breakpoint index is guaranteed to only ever increment in runner.py but i suppose that doesnt prevent e.g. breakpoint with repr -> breakpoint without repr -> breakpoint with repr from causing issues. I dont think the tests ever do that? But better safe than sorry for sure.
There was a problem hiding this comment.
Yeah that doesn't sound all that far fetched. I'd rather if the code didn't have too many similar assumptions, especially since crashes or logic bugs in the Python layer might be quite difficult to discover and debug.
There was a problem hiding this comment.
Should be taken care of now. --bless will output a blank breakpoint if it encounters any skipped breakpoints, so indexing into the list should never fail (i added error handling anyway just in case). Outputting empty breakpoints isn't ideal, but it's almost certainly rare enough that it's cheaper than converting breakpoints to dict[int, ...].
| def check(var_name: str, breakpoint_idx: int, frame: lldb.SBFrame) -> Result: | ||
| """`lldb-repr` pseudo-command entrypoint. Checks the variable against `INPUT_DATA` for the given | ||
| frame at the given breakpoint. | ||
| frame at the given breakpoint. Returns True if a |
There was a problem hiding this comment.
Maybe we should set --batch to ensure that LLDB will always end after executing the given script commands?
I had some troubles testing this on LLDB 18. I know that it is an ancient version, but I still wonder about if we are making assumptions that might only hold for specific LLDB version too much.
- stderr is not propagated outside of the debugger script. Only stdout is.
LLDB_ARCH_DEFAULTissystemArch, and passing it todebugger.CreateTargetWithFileAndArchends with an error (error: unable to find a plug-in for the platform named "systemArch")- Using
SBDebugger::CreateTargetWithFileAndTargetTriplejust hangs (probably some UB/segfault happens?)
Maybe LLDB 18 is just broken too much to have any hope of running this script? It works with LLDB 22, except for stderr, which just doesn't seem to be propagated.
| @@ -469,11 +469,21 @@ impl TestCx<'_> { | |||
| // make sure `PATH` points to all the dlls necessary to run the debugee | |||
| let path = prepend_to_path(&self.config.target_run_lib_path); | |||
|
|
|||
| // Output the file path of the input data for `lldb-repr` commands | |||
| let lldb_input_data_path = self.config.src_root.join(format!( | |||
There was a problem hiding this comment.
I'd rather turn each test into a directory and store the files next to the Rust file with the code.
| target: lldb.SBTarget = debugger.CreateTarget( | ||
| target_path, None, None, True, target_error | ||
| ) |
There was a problem hiding this comment.
| target: lldb.SBTarget = debugger.CreateTarget( | |
| target_path, None, None, True, target_error | |
| ) | |
| target_triple = get_env_arg("LLDB_BATCHMODE_TARGET_TRIPLE") | |
| target: lldb.SBTarget = debugger.CreateTarget( | |
| target_path, target_triple, None, True, target_error | |
| ) |
Setting None for the target triple segfaults my LLDB 18. The C++ code dereferences that pointer (?), so it shouldn't be NULL.
There was a problem hiding this comment.
I unfortunately dont have a copy of lldb 18 handy. Does the following work?
lldb.debugger.CreateTargetWithFileAndTargetTriple(
target_path,
lldb.SBPlatform.GetHostPlatform().GetTriple()
)There was a problem hiding this comment.
No, it also get stuck. But nevermind, LLDB 18 is old and we shouldn't try to support it. I downloaded LLDB 22 to be able to test this.
There was a problem hiding this comment.
Oh, it just occurred to me that even if this function worked in lldb 18, importing from_lldb.py wouldn't because it uses a constant that doesn't exist prior to lldb 22 (lldb.eBasicTypeFloat128).
I did check (for sanity's sake) and all other eBasicType values have existed for 14-15 years except for char8 which was added in 2022, which is about 2 years prior to lldb 18 releasing
There was a problem hiding this comment.
It seems that stderr is not propagated outside of the debugger script? I'd suggest printing everything to stdout instead.
|
Converted 1 more test to help confirm the last bits of the comparison logic. The 4 converted tests cover the core functionality: primitives, non-primitive builtins (slice, str), some of our standard container types (with generics, and with synthetic and summary providers), and sum-type, niche-optimized enums (which are a huge pain in general).
I'll give this a try later today. It definitely sounds ideal, but I want to make sure it preserves the exit status code and doesn't somehow break everything when we run commands in the |
7d4c512 to
9000709
Compare
|
That should do it for all the major checks. Here are some example error messages for the variable side of things: Synthetic throwing exceptionsFor this error I just commented out the part of Further down in the same error message, we get an error for We also have the summary error: Synthetic/Summary not registeredFor this, i just commented out the code that registers the And OsString reports: Too many childrenThe following is reported when adding an additional element to the vec in Summary throws exceptionFor this error, I just set the first line of Mismatching `BasicType`/`TypeClass`For these, the error will seem "backwards" because I had to edit the test data: I know performance isn't the most important concern, but I wanted to make sure I wasn't absolutely destroying the run time of the test suite (python being python and all). From a really scuffed benchmark of a passing test (the error path is obviously much slower due to both the additional logic, and needing to print way more stuff):
So, I'd guess quite a bit slower than the old string-based checks, but not horrible considering the quality of the errors. I've got some experience writing performance-sensitive python, so I can always clean this up and reduce the runtime more later. There's definitely some redundant iteration and such in the error checking, but I was more concerned with keeping things simple and easy to reason about. |
|
Some changes occurred in src/tools/compiletest cc @jieyouxu
|
There was a problem hiding this comment.
I'll just note that this PR kind of grown out of proportions 😆 Some of the separate functionality, like nice printing of errors, could definitely land in separate PRs, the next time (fine by me to keep it in this PR to avoid splitting complexity). I hope we'll have enough of the base infra landed so that follow-up changes can be done more incrementally, because reviewing 3k diffs (even if some of that is JSON) is.. ooh :)
Otherwise it looks good.
There was a problem hiding this comment.
There are trade-offs for both approaches, but once we use a directory, maybe we could name the debugged file main.rs or something? Like we do for runmake tests (where every test is named rmake.rs).
There was a problem hiding this comment.
I think that using directories with an entry point or such seems very reasonable
Very much so a work in progress, but there's a bunch of stuff that probably needs discussing, so I figured I'd start that up now.
To recap, the control flow is as follows:
lldb-repris automatically split into, essentiallylldb-command:repr var+lldb-check:var: Oklldb_batchmode.main()reprpseudo-command, it is intercepted and passed to the checking logic5a. if blessing,
INPUT_DATAis blank. Each check inserts the appropriate var intoINPUT_DATA, and then runs the checking logic againstINPUT_DATAas normal (for sanity reasons)5b. the checking logic checks the variable against
INPUT_DATA(<-- this is incomplete atm, see below for what still isn't finished) and prints any mismatches that occur.quit/exitcommand is encountered)lldb_batchmodechecks 1. have we seen every type that exists in the input data? 2. have we seen every variable that exists in the input data? If not, it reports what was missing and exits with an error code.6a. If
--bless, and no errors occurred, and at least 1reprpseudo-command was processed,INPUT_DATAis serialized and written to the input data file.To preemptively answer the question "When blessing, why not just build a second
TargetDatainstance and compareINPUT_DATAto that?" - the goal of diffing in python (rather than rust) is to still have access to the underlying LLDB objects for error reporting purposes.Sample Output (`basic-types.rs`)
The input data was manually tampered with to force errors (`char32_t` size set to 1, double type renamed to `half`, `int` type deleted)error: Error while running LLDB status: exit status: 1 ... # skipping to repr output for brevity repr b b: Ok repr i i: Ok repr c [repr error: type 'char32_t'] size does not match. Expected: '1' Got: '4' repr i8 i8: Ok repr i16 i16: Ok repr i32 i32: Ok repr i64 i64: Ok repr u u: Ok repr u8 u8: Ok repr u16 u16: Ok repr u32 [repr error: type 'unsigned int'] type not found in input data repr u64 u64: Ok repr f32 f32: Ok repr f64 [repr error: type 'double'] type not found in input data [repr error] The following types were expected, but were not tested: {'half'}Sample Output (`simple-struct.rs`)
The input data was manually tampered with to force errors.simple_struct::NoPadding64field nameytoqsimple_struct::NoPadding163264last field moved to first positionsimple_struct::InternalPaddingyfield deletedsimple_struct::PaddingAtEndqfield addedKeep in mind that I edited the expected data, not the actual structs in the test file, so the output reports the opposite of the changes i made (sortof) i.e. it reports that
qwas deleted because it exists in the expected data but not in the LLDB object.repr no_padding16 no_padding16: Ok repr no_padding32 no_padding32: Ok repr no_padding64 [repr error: type 'simple_struct::NoPadding64'] The following field(s) appear to have been renamed. If this is expected, consider rerunning with the `--bless` option: ['q -> y'] repr no_padding163264 [repr error: type 'simple_struct::NoPadding163264'] Field(s) appear to have been rearranged. If this was expected, try re-running with the `--bless` option Expected: [ Field(name='a', type='short', offset=12), Field(name='b', type='unsigned short', offset=14), Field(name='c', type='int', offset=8), Field(name='d', type='unsigned long', offset=0)] Got: [ Field(name='d', type='unsigned long', offset=0), Field(name='a', type='short', offset=12), Field(name='b', type='unsigned short', offset=14), Field(name='c', type='int', offset=8)] repr internal_padding [repr error: type 'simple_struct::InternalPadding'] The following field(s) appear to have been added to the type: {Field(name='y', type='long', offset=0)} repr padding_at_end [repr error: type 'simple_struct::PaddingAtEnd'] The following field(s) appear to have been removed from the type: {Field(name='q', type='float', offset=12)} [repr error] The following types were expected, but were not tested: {'double', 'long', 'unsigned long'}The errors are of the form
[repr error <error source>] <error info>. The errors are slightly indented to make it easier to scan and associate errors with their source. The formatting is 1st draft and largely abstracted away via these functions. We can pretty trivially change how they're formatted by modifying/replacing these functions.Also, each type in a test is only tested once per test, regardless of how many variables/fields reference it. When a type is seen a second time, if the prior check was a mismatch, it reports that the type does not match and does not repeat the specific error messages of the mismatch. Instead, it directs people to look at the original type error further up in the output.
TODO
lldb_providersand the originalSBValueandSBTypeto improve error messagesu8/i8at some point to test that too).r? @jieyouxu, @Kobzol