Skip to content
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

Cannot debug values inside some if-statements: [sentinel kind: OptimizedOut] from evaluateInFrame() #52430

Closed
vital-edu opened this issue May 17, 2023 · 15 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on vm-debugger

Comments

@vital-edu
Copy link

vital-edu commented May 17, 2023

When I try to evaluate values within if statements in the debug console the following error appears:

[Sentinel kind: OptimizedOut, valueAsString: <optimized out>] from evaluateInFrame()
#0      DartDebugAdapter.evaluateRequest (package:dds/src/dap/adapters/dart.dart:995:7)
<asynchronous suspension>
#1      BaseDebugAdapter.handle (package:dds/src/dap/base_debug_adapter.dart:143:7)
<asynchronous suspension>

Snippet that reproduces the issue (add the breakpoints in the line below the comments).

void main() {
  var data = {
    'number': 20,
    'canProcess': true,
  };
  final worker = Worker(data);
  print(worker.result);

  final result = worker.maybeProcess(data, (data) {
    if (data is Map) {
      // Breakpoint 2: without issue
      return data['number'] % 2 == 0;
    }
    return null;
  });

  print(result);

  print(worker.getResult());
  print(dataHasEventNumber(data));
}

class Worker {
  final dynamic _data;

  Worker(this._data);

  bool? get result {
    return maybeProcess(_data, (data) {
      if (data is Map) {
        // Breakpoint 1: with issue
        return data['number'] % 2 == 0;
      }
      return null;
    });
  }

  bool? getResult() {
    return maybeProcess(_data, (data) {
      if (data is Map) {
        // Breakpoint 3: with issue
        return data['number'] % 2 == 0;
      }
      return null;
    });
  }

  bool? maybeProcess<String>(dynamic data, bool? Function(dynamic) fun) {
    if (data is Map && data['canProcess'] == true) {
      return fun(data);
    }

    return null;
  }
}

bool? dataHasEventNumber(data) {
  if (data is Map) {
    // Breakpoint 4: without issue
    return data['number'] % 2 == 0;
  }
  return null;
}

Tested on flutter master and flutter stable channels, using VSCode (printing the value in the Debug Console) or Android Studio (evaluating expression).

Master channel: Dart SDK version: 3.1.0-118.0.dev (dev) (Tue May 16 18:58:22 2023 -0700) on "macos_x64"
Stable channel: Dart SDK version: 3.0.1 (stable) (Tue May 16 11:57:19 2023 +0000) on "macos_x64"

This bug does not exist on Dart SDK version: 2.19.2 (stable) (Tue Feb 7 18:37:17 2023 +0000) on "macos_x64"

@vital-edu vital-edu changed the title Cannot debug values inside some If-case statements: [sentinel kind: OptimizedOut] from evaluateInFrame() Cannot debug values inside some if-statements: [sentinel kind: OptimizedOut] from evaluateInFrame() May 17, 2023
@lrhn lrhn added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label May 17, 2023
@a-siva
Copy link
Contributor

a-siva commented May 17, 2023

//cc @derekxu16

@DanTup
Copy link
Collaborator

DanTup commented May 25, 2023

I've had this report from a number of VS Code users too (there's an open issue at Dart-Code/Dart-Code#4555). I can reproduce it in some cases (using functions not if statements), though only in Flutter apps.

Below is a Flutter app repro. It has two debugger() calls in two functions that are the same. One is in main() and hovering over aaa works fine. The second is the same in the build method, but the evaluations fail with "".

import 'dart:developer';

import 'package:flutter/material.dart';

void main() {
  (int aaa) {
    debugger();
    print(aaa); // hover over aaa WORKS
  }(1);

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    (int aaa) {
      debugger();
      print(aaa); // hover over aaa DOES NOT WORK
    }(1);
    return const MaterialApp();
  }
}

Working VM request/response:

==> {
    "id": "695",
    "jsonrpc": "2.0",
    "method": "evaluateInFrame",
    "params": {
        "disableBreakpoints": true,
        "expression": "aaa",
        "frameIndex": 0,
        "isolateId": "isolates/708117027186575"
    }
}

<== {
    "jsonrpc": "2.0",
    "result": {
        "type": "@Instance",
        "_vmType": "Smi",
        "class": {
           // snip
        },
        "identityHashCode": 0,
        "kind": "Int",
        "fixedId": true,
        "id": "objects/int-1",
        "valueAsString": "1"
    },
    "id": "695"
}

Not working VM request/response:

==> {
    "id": "699",
    "jsonrpc": "2.0",
    "method": "evaluateInFrame",
    "params": {
        "disableBreakpoints": true,
        "expression": "aaa",
        "frameIndex": 0,
        "isolateId": "isolates/708117027186575"
    }
}

<== {
    "jsonrpc": "2.0",
    "result": {
        "type": "Sentinel",
        "kind": "OptimizedOut",
        "valueAsString": "<optimized out>"
    },
    "id": "699"
}

@starball5
Copy link

starball5 commented May 26, 2023

Related to this and Dart-Code/Dart-Code#4555 on Stack Overflow:

Updated answer posted here

@DanTup
Copy link
Collaborator

DanTup commented Jun 1, 2023

@bkonyi any thoughts on this? It was noted a few times in #52574 but I believe it's a different issue. It occurs at breakpoints and happens with both debug adapters. I included a simple repro above.

@bkonyi
Copy link
Contributor

bkonyi commented Jun 2, 2023

I'm not sure why one case works but the other doesn't. Maybe @alexmarkov might know why aaa is optimized out in one case and not the other?

@alexmarkov
Copy link
Contributor

@bkonyi This happens because build method is an instance method, and main is static.
The closure in the build method doesn't use this, so it is not captured in the closure context. But debugger requires this in order to evaluate expression in the context of an instance method:

sdk/runtime/vm/debugger.cc

Lines 1139 to 1142 in 8dfd804

if (receiver.ptr() == Object::optimized_out().ptr()) {
// Cannot execute an instance method without a receiver.
return Object::optimized_out().ptr();
}

This limitation was added in 79bcad6. Maybe we can relax that condition in case evaluated expression doesn't use this. /cc @rmacnak-google

@bkonyi
Copy link
Contributor

bkonyi commented Jun 5, 2023

Ah, that makes sense. Based on the number of 👍 on the issue, we should try and relax that condition if we can. Can you take a look at this @rmacnak-google?

@markalroberts
Copy link

Hi - any update on this? I believe downgrading to 3.7.12 may fix this, but I now have a few dependencies that need SDK>=3.0.0 and so I will need to downgrade these dependencies too...

@a-siva a-siva added the P2 A bug or feature request we're likely to work on label Jul 5, 2023
@a-siva
Copy link
Contributor

a-siva commented Jul 5, 2023

//cc @derekxu16 could you take a look at this.

@Rexios80
Copy link
Contributor

ETA on release? This has been making debugging quite difficult

@a-siva
Copy link
Contributor

a-siva commented Jul 11, 2023

ETA on release? This has been making debugging quite difficult

This fix should be in Dart 3.1 Beta 3/ Flutter 3.13 (beta channel) which is slated for release on July 12th 2023 and would make it into the stable release channel on 16 August 2023

@JCKodel
Copy link

JCKodel commented Jul 11, 2023

I wonder: how bad a bug must be to be cherry-picked. O.o

@a-siva
Copy link
Contributor

a-siva commented Jul 11, 2023

I wonder: how bad a bug must be to be cherry-picked. O.o

Usually we consider regressions that cause deployed app crashes or incorrect behaviour in the deployed app for cherry picks. This bug affects debugging and developers can potentially switch to the latest beta channel for development to address the issue. Having said that if enough people think that it is critical to cherry pick this fix into the previous stable release we could consider doing a cherry pick, the earliest that cherry pick could happen would be July 19th 2023 which is later than the Dart 3.1 beta 3 release date.

@FirdousNath
Copy link

FirdousNath commented Jul 17, 2023

Why this issue is closed if not fixed or released ? @rmacnak-google @bkonyi

@bkonyi
Copy link
Contributor

bkonyi commented Jul 17, 2023

The issue is fixed on the main branch and was released with the last beta. We don't keep issues open until they've made it into a beta / release branch because all the relevant work has been completed and leaving the issue open makes it more difficult to track what has or hasn't been completed.

Since this issue has been fixed and there's no work left to be done, I'm going to lock this thread. Please file another issue if you're still encountering this problem on the beta branch.

@dart-lang dart-lang locked as resolved and limited conversation to collaborators Jul 17, 2023
copybara-service bot pushed a commit that referenced this issue Oct 17, 2023
…iledExpression when paused inside a closure

TEST=pkg/vm_service/test/evaluate_inside_closures_test.dart, pkg tryjob

Fixes: #52430
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/313001
Cherry-pick-request: #53747
Change-Id: Ib3479a0b39377ea20765752fd91fef26e8f46454
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330248
Reviewed-by: Derek Xu <derekx@google.com>
Commit-Queue: Kevin Chisholm <kevinjchisholm@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on vm-debugger
Projects
None yet
Development

No branches or pull requests