Add V8StackFrame export

To be able to retrieve structured stacktrace information like the
functionName of single stack frames outsite of v8, this cl adds a
V8StackFrame class and a function to retrieve them from V8StacKFrames.

Bug: chromium:1393317
Change-Id: Idae150aeb03f7b65294c4c6a6979c298a569e6d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4067040
Reviewed-by: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Judith Hemp <hempjudith@google.com>
Cr-Commit-Position: refs/heads/main@{#84676}
This commit is contained in:
Judith Hemp 2022-12-06 09:48:23 +01:00 committed by V8 LUCI CQ
parent 4b565358d6
commit 8ef8a016dc
3 changed files with 33 additions and 4 deletions

View File

@ -32,19 +32,19 @@ namespace Debugger {
namespace API {
class SearchMatch;
}
}
} // namespace Debugger
namespace Runtime {
namespace API {
class RemoteObject;
class StackTrace;
class StackTraceId;
}
}
} // namespace API
} // namespace Runtime
namespace Schema {
namespace API {
class Domain;
}
}
} // namespace Schema
} // namespace protocol
class V8_EXPORT StringView {
@ -134,6 +134,13 @@ class V8_EXPORT V8DebuggerId {
int64_t m_second = 0;
};
struct V8_EXPORT V8StackFrame {
StringView sourceURL;
StringView functionName;
int lineNumber;
int columnNumber;
};
class V8_EXPORT V8StackTrace {
public:
virtual StringView firstNonEmptySourceURL() const = 0;
@ -151,6 +158,8 @@ class V8_EXPORT V8StackTrace {
// Safe to pass between threads, drops async chain.
virtual std::unique_ptr<V8StackTrace> clone() = 0;
virtual std::vector<V8StackFrame> frames() const = 0;
};
class V8_EXPORT V8InspectorSession {

View File

@ -1,4 +1,5 @@
// Copyright 2016 the V8 project authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@ -10,6 +11,8 @@
#include "src/inspector/v8-stack-trace-impl.h"
#include <algorithm>
#include <memory>
#include <vector>
#include "../../third_party/inspector_protocol/crdtp/json.h"
#include "src/debug/debug-interface.h"
@ -313,6 +316,21 @@ StringView V8StackTraceImpl::topFunctionName() const {
return toStringView(m_frames[0]->functionName());
}
std::vector<V8StackFrame> V8StackTraceImpl::frames() const {
std::vector<V8StackFrame> ret;
ret.reserve(m_frames.size());
for (const auto& frame : m_frames) {
if (frame) {
ret.emplace_back(V8StackFrame{
toStringView(frame->sourceURL()), toStringView(frame->functionName()),
frame->lineNumber() + 1, frame->columnNumber() + 1});
}
}
return ret;
}
std::unique_ptr<protocol::Runtime::StackTrace>
V8StackTraceImpl::buildInspectorObjectImpl(V8Debugger* debugger) const {
return buildInspectorObjectImpl(debugger, m_maxAsyncDepth);

View File

@ -84,6 +84,8 @@ class V8StackTraceImpl : public V8StackTrace {
bool isEqualIgnoringTopFrame(V8StackTraceImpl* stackTrace) const;
std::vector<V8StackFrame> frames() const override;
private:
V8StackTraceImpl(std::vector<std::shared_ptr<StackFrame>> frames,
int maxAsyncDepth,