Skip to content

Add Dart API method for getting current stack trace. #2573

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

Closed
DartBot opened this issue Apr 16, 2012 · 19 comments
Closed

Add Dart API method for getting current stack trace. #2573

DartBot opened this issue Apr 16, 2012 · 19 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@DartBot
Copy link

DartBot commented Apr 16, 2012

This issue was originally filed by [email protected]


This is needed to implement console.trace() which dumps current stack trace to inspector console.

@DartBot
Copy link
Author

DartBot commented Apr 16, 2012

This comment was originally written by @mhausner


When a breakpoint is hit, the breakpoint handler receives a handle to the stack trace. I will add a separate call to retrieve the current stack trace.


Set owner to @mhausner.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Jun 8, 2012

This comment was originally written by @mhausner


This functionality has been added. Closing the issue.


Added Fixed label.

@DartBot
Copy link
Author

DartBot commented Jul 18, 2012

This comment was originally written by [email protected]


Looks like Dart_GetStackTrace works only from breakpoint handler.

To properly implement console.log we need a function that returns current stack trace when vm is not actually paused, like v8::StackTrace::CurrentStackTrace does.

Matthias, could you please fix the Dart_GetStackTrace function so that it works from arbitrary embedder's callback?


Added Triaged label.

@DartBot
Copy link
Author

DartBot commented Jul 18, 2012

This comment was originally written by @mhausner


This feature request depends on the functionality to stop the VM from another thread, which is currently not implemented. At this point, we consider this a lower priority issue.


Added this to the Later milestone.
Added Accepted label.

@DartBot
Copy link
Author

DartBot commented Jul 19, 2012

This comment was originally written by [email protected]


Why do we need to stop the VM from another thread to get current stack trace of an isolate in a native function?

Here is some context:
In dart:
class Console { void log(obj) native "Console_log_callback" }

In c++:
void Console_log_callback(Dart_NativeArguments args) {
  // (pseudo code)
  ConsoleMessage message = new ConsoleMessage(Dart_GetNativeArgument(args, 1));
  Dart_Handle stackTrace = Dart_GetStackTrace();
  Vector<Frame> frames;
  for (int i = 0; i < Length(stackTrace); ++i) {
    Dart_Handle activationFrame = ActivationFrameAt(stackTrace, i);
    frames.add(new Frame(ScriptUrl(activationFrame), LineNumber(activationFrame)));
  }
  message.setCallFrames(frames);
}

Here is a very rough implementation of what is needed https://chromiumcodereview.appspot.com/10808032/.
A link from print's output in console to the corresponding source code line is a very useful debugger feature. Would be nice to have it.

Sorry for not stating the problem clearly from the beginning.

@DartBot
Copy link
Author

DartBot commented Jul 19, 2012

This comment was originally written by @mhausner


You want a stack trace of an isolate that is "not actually paused" as you say above. I interpret this as "an isolate that is currently running code". That's why I said we need a way to stop the isolate to collect the stack trace.

If you are talking about an isolate that is not currently running (but not paused), then it's easier. But in that case, the stack is empty, isn't it?

I still don't know what exactly it is you would like to have...
 

@DartBot
Copy link
Author

DartBot commented Jul 19, 2012

This comment was originally written by [email protected]


Why do you expect the stack trace to be empty while executing a c++ calback? There should always be at least one dart frame which invoked the native function.

@DartBot
Copy link
Author

DartBot commented Oct 15, 2012

This comment was originally written by [email protected]


Issue #5851 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Oct 15, 2012

This comment was originally written by [email protected]


Marked this as blocking #5851.

@DartBot
Copy link
Author

DartBot commented Oct 15, 2012

This comment was originally written by @mhausner


Added debugger label.

@iposva-google
Copy link
Contributor

Removed Priority-Medium label.
Added Priority-Unassigned label.

@jacob314
Copy link
Member

Removed this from the Later milestone.
Added this to the M7 milestone.
Removed Priority-Unassigned label.
Added Priority-Medium label.

@iposva-google
Copy link
Contributor

Do I understand this request as equivalent to calling this helper method in Dart from a native method?

_getStackTrace() {
  try {
    throw "A";
  } catch (e, s) {
    return s.toString();
  }
}


cc @a-siva.
Removed this from the M7 milestone.
Removed Priority-Medium label.
Added Priority-Unassigned label.

@iposva-google
Copy link
Contributor

Siva, this request came from Dartium land. Is this still an issue?

@iposva-google
Copy link
Contributor

Unmarked this as blocking #5851.

@iposva-google
Copy link
Contributor

Removed debugger label.
Added NotPlanned label.

@jacob314
Copy link
Member

This isn't a high priority Dartium issue at the moment. It would be nice if we had direct support like V8 does.
Currently we have to do the following which is a little ugly. captureParsedStackTrace is a method like the one iposva suggests.

    Dart_ExceptionPauseInfo previousPauseInfo = Dart_GetExceptionPauseInfo();
    if (previousPauseInfo != kNoPauseOnExceptions)
        Dart_SetExceptionPauseInfo(kNoPauseOnExceptions);
    Dart_Handle exception = 0;
    Dart_Handle parsedStackTrace = DartUtilities::invokeUtilsMethod("captureParsedStackTrace", 0, 0);

    if (previousPauseInfo != kNoPauseOnExceptions)
        Dart_SetExceptionPauseInfo(previousPauseInfo);

@blois
Copy link

blois commented Jan 2, 2014

I'm wondering if we can revisit the decision to not do this- the primary issue that I see is that relying on throwing exceptions causes issues with 'break on all exceptions'.

For example, Angular tests log the stack trace with all injections (https://github.com/angular/angular.dart/blob/9d190120f329bb766c7291dd96eb2f62b23f6f2f/lib/mock/test_injection.dart#L84), which throws hundreds of exceptions on start.

This makes it incredibly difficult to debug these tests.

In JS, this can be accomplished by using 'new Error().stack'

@a-siva
Copy link
Contributor

a-siva commented Jan 2, 2014

This bug is for a request to provide a mechanism for getting a stack trace from the C/C++ Dart API. The example you have above with the Angular test case is more a request for a stacktrace from Dart code. I think you should redirect that to the library team.

@DartBot DartBot added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-not-planned Closed as we don't intend to take action on the reported issue labels Jan 2, 2014
dart-bot pushed a commit that referenced this issue Aug 11, 2020
> git log --oneline 04b054b62cc437cf23451785fdc50e49cd9de139..master
0d185a39 (HEAD -> master, origin/master, origin/HEAD) Push null-safety forwards to 2.11 (#2604)
56f9f27f Hide outdated --mode flag (#2603)
61ce6f81 Avoid double loop (#2605)
fa6e57d7 (disable_mixed_mode_validation) Fix outdated latest ordering (#2598)
6549e4aa Remove unused dependency from pubspec.yaml (#2592)
61543d07 Don't look for external package foo during testing (#2599)
590b448f Fixed license headers (#2595)
04e0601e Don't show entries for dev-dependencies in outdated --json --no-dev-dependencies (#2591)
8c3778c4 Configure GitHub move app (#2578)
eec7beca (top_level_command) Pass --(no-)sound-null-safety arg through to VM. (#2542)
152e4740 Warn about publishing in mixed mode (#2583)
0b7a3abe Removed april fools toys (#2325)
b74a5b73 Actually print hints (#2582)
8ec3a66d (pub2) Fix outdated --no-color (#2572)
7bb3d4e6 Use getSdkPath() in NullSafetyAnalysis (#2573)
3c578f24 Drop the "magic" package concept (#2577)
0e967ff0 Remove unused function (#2570)
988fefef Remove dependency overrides (#2568)

Change-Id: I58bf14234ed55bf9d825de60a40ded1d65281195
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158003
Reviewed-by: Jonas Jensen <[email protected]>
Commit-Queue: Sigurd Meldgaard <[email protected]>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

5 participants