Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1109)

Unified Diff: runtime/vm/debugger.cc

Issue 1644793002: Replace intptr_t with TokenDescriptor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/debugger.cc
diff --git a/runtime/vm/debugger.cc b/runtime/vm/debugger.cc
index 1b3d84a97e441602c1a7ec5cce5838387b56109a..25ed8d6cb1955cf231f6072c899c061b445dccc0 100644
--- a/runtime/vm/debugger.cc
+++ b/runtime/vm/debugger.cc
@@ -27,6 +27,7 @@
#include "vm/stub_code.h"
#include "vm/symbols.h"
#include "vm/thread_interrupter.h"
+#include "vm/token_descriptor.h"
#include "vm/visitor.h"
@@ -67,8 +68,8 @@ class RemoteObjectCache : public ZoneAllocated {
// Create an unresolved breakpoint in given token range and script.
BreakpointLocation::BreakpointLocation(const Script& script,
- intptr_t token_pos,
- intptr_t end_token_pos,
+ TokenDescriptor token_pos,
+ TokenDescriptor end_token_pos,
intptr_t requested_line_number,
intptr_t requested_column_number)
: script_(script.raw()),
@@ -84,7 +85,7 @@ BreakpointLocation::BreakpointLocation(const Script& script,
line_number_(-1),
column_number_(-1) {
ASSERT(!script.IsNull());
- ASSERT(Token::IsReal(token_pos_));
+ ASSERT(TokenDescriptor(token_pos_).IsReal());
}
// Create a latent breakpoint at given url and line number.
@@ -93,8 +94,8 @@ BreakpointLocation::BreakpointLocation(const String& url,
intptr_t requested_column_number)
: script_(Script::null()),
url_(url.raw()),
- token_pos_(Token::kNoSourcePos),
- end_token_pos_(Token::kNoSourcePos),
+ token_pos_(TokenDescriptor::kNoSource),
+ end_token_pos_(TokenDescriptor::kNoSource),
is_resolved_(false),
next_(NULL),
conditions_(NULL),
@@ -122,7 +123,8 @@ bool BreakpointLocation::AnyEnabled() const {
}
-void BreakpointLocation::SetResolved(const Function& func, intptr_t token_pos) {
+void BreakpointLocation::SetResolved(const Function& func,
+ TokenDescriptor token_pos) {
ASSERT(!IsLatent());
ASSERT(func.script() == script_);
ASSERT((func.token_pos() <= token_pos) &&
@@ -140,11 +142,11 @@ void BreakpointLocation::SetResolved(const Function& func, intptr_t token_pos) {
// in more than one library, e.g. the text location of mixin functions.
void BreakpointLocation::GetCodeLocation(Library* lib,
Script* script,
- intptr_t* pos) const {
+ TokenDescriptor* pos) const {
if (IsLatent()) {
*lib = Library::null();
*script = Script::null();
- *pos = -1;
+ *pos = TokenDescriptor::kNoSource;
} else {
*script = this->script();
*pos = token_pos_;
@@ -239,7 +241,7 @@ ActivationFrame::ActivationFrame(
code_(Code::ZoneHandle(code.raw())),
function_(Function::ZoneHandle(code.function())),
token_pos_initialized_(false),
- token_pos_(Token::kNoSourcePos),
+ token_pos_(TokenDescriptor::kNoSource),
try_index_(-1),
line_number_(-1),
column_number_(-1),
@@ -451,7 +453,7 @@ const char* Debugger::QualifiedFunctionName(const Function& func) {
// Returns true if function contains the token position in the given script.
static bool FunctionContains(const Function& func,
const Script& script,
- intptr_t token_pos) {
+ TokenDescriptor token_pos) {
if ((func.token_pos() <= token_pos) && (token_pos <= func.end_token_pos())) {
// Check script equality second because it allocates
// handles as a side effect.
@@ -563,10 +565,10 @@ void ActivationFrame::GetPcDescriptors() {
// Compute token_pos_ and try_index_ and token_pos_initialized_.
-intptr_t ActivationFrame::TokenPos() {
+TokenDescriptor ActivationFrame::TokenPos() {
if (!token_pos_initialized_) {
token_pos_initialized_ = true;
- token_pos_ = Token::kNoSourcePos;
+ token_pos_ = TokenDescriptor::kNoSource;
GetPcDescriptors();
PcDescriptors::Iterator iter(pc_desc_, RawPcDescriptors::kAnyKind);
uword pc_offset = pc_ - code().EntryPoint();
@@ -592,8 +594,8 @@ intptr_t ActivationFrame::TryIndex() {
intptr_t ActivationFrame::LineNumber() {
// Compute line number lazily since it causes scanning of the script.
- if ((line_number_ < 0) && Token::IsReal(TokenPos())) {
- const intptr_t token_pos = TokenPos();
+ if ((line_number_ < 0) && TokenPos().IsReal()) {
+ const TokenDescriptor token_pos = TokenPos();
const Script& script = Script::Handle(SourceScript());
script.GetTokenLocation(token_pos, &line_number_, NULL);
}
@@ -603,8 +605,8 @@ intptr_t ActivationFrame::LineNumber() {
intptr_t ActivationFrame::ColumnNumber() {
// Compute column number lazily since it causes scanning of the script.
- if ((column_number_ < 0) && Token::IsReal(TokenPos())) {
- const intptr_t token_pos = TokenPos();
+ if ((column_number_ < 0) && TokenPos().IsReal()) {
+ const TokenDescriptor token_pos = TokenPos();
const Script& script = Script::Handle(SourceScript());
if (script.HasSource()) {
script.GetTokenLocation(token_pos, &line_number_, &column_number_);
@@ -649,14 +651,14 @@ intptr_t ActivationFrame::ContextLevel() {
// for the code position of the frame? For now say we are at context
// level 0.
TokenPos();
- if (token_pos_ == -1) {
+ if (token_pos_ == TokenDescriptor::kNoSource) {
// No PcDescriptor.
return context_level_;
}
ASSERT(!pc_desc_.IsNull());
- intptr_t innermost_begin_pos = 0;
- intptr_t activation_token_pos = TokenPos();
- ASSERT(Token::IsReal(activation_token_pos));
+ TokenDescriptor innermost_begin_pos = TokenDescriptor::kMinSource;
+ TokenDescriptor activation_token_pos = TokenPos();
+ ASSERT(activation_token_pos.IsReal());
GetVarDescriptors();
intptr_t var_desc_len = var_descriptors_.Length();
for (intptr_t cur_idx = 0; cur_idx < var_desc_len; cur_idx++) {
@@ -768,8 +770,8 @@ void ActivationFrame::GetDescIndices() {
}
GetVarDescriptors();
- intptr_t activation_token_pos = TokenPos();
- if (!Token::IsDebugPause(activation_token_pos)) {
+ TokenDescriptor activation_token_pos = TokenPos();
+ if (!activation_token_pos.IsDebugPause()) {
// We don't have a token position for this frame, so can't determine
// which variables are visible.
vars_initialized_ = true;
@@ -929,8 +931,8 @@ void ActivationFrame::PrintContextMismatchError(
void ActivationFrame::VariableAt(intptr_t i,
String* name,
- intptr_t* token_pos,
- intptr_t* end_pos,
+ TokenDescriptor* token_pos,
+ TokenDescriptor* end_pos,
Object* value) {
GetDescIndices();
ASSERT(i < desc_indices_.length());
@@ -998,7 +1000,7 @@ RawArray* ActivationFrame::GetLocalVariables() {
Object& value = Instance::Handle();
const Array& list = Array::Handle(Array::New(2 * num_variables));
for (intptr_t i = 0; i < num_variables; i++) {
- intptr_t ignore;
+ TokenDescriptor ignore;
VariableAt(i, &var_name, &ignore, &ignore, &value);
list.SetAt(2 * i, var_name);
list.SetAt((2 * i) + 1, value);
@@ -1013,7 +1015,7 @@ RawObject* ActivationFrame::GetReceiver() {
String& var_name = String::Handle();
Instance& value = Instance::Handle();
for (intptr_t i = 0; i < num_variables; i++) {
- intptr_t ignore;
+ TokenDescriptor ignore;
VariableAt(i, &var_name, &ignore, &ignore, &value);
if (var_name.Equals(Symbols::This())) {
return value.raw();
@@ -1038,7 +1040,7 @@ RawObject* ActivationFrame::Evaluate(const String& expr) {
Object& value = Instance::Handle();
intptr_t num_variables = desc_indices_.length();
for (intptr_t i = 0; i < num_variables; i++) {
- intptr_t ignore;
+ TokenDescriptor ignore;
VariableAt(i, &name, &ignore, &ignore, &value);
if (!name.Equals(Symbols::This())) {
if (IsPrivateVariableName(name)) {
@@ -1109,8 +1111,8 @@ void ActivationFrame::PrintToJSONObject(JSONObject* jsobj,
for (intptr_t v = 0; v < num_vars; v++) {
String& var_name = String::Handle();
Instance& var_value = Instance::Handle();
- intptr_t token_pos;
- intptr_t end_token_pos;
+ TokenDescriptor token_pos;
+ TokenDescriptor end_token_pos;
VariableAt(v, &var_name, &token_pos, &end_token_pos, &var_value);
if (var_name.raw() != Symbols::AsyncOperation().raw()) {
JSONObject jsvar(&jsvars);
@@ -1121,8 +1123,8 @@ void ActivationFrame::PrintToJSONObject(JSONObject* jsobj,
// TODO(turnidge): Do we really want to provide this on every
// stack dump? Should be associated with the function object, I
// think, and not the stack frame.
- jsvar.AddProperty("_tokenPos", token_pos);
- jsvar.AddProperty("_endTokenPos", end_token_pos);
+ jsvar.AddProperty("_tokenPos", token_pos.value());
+ jsvar.AddProperty("_endTokenPos", end_token_pos.value());
}
}
}
@@ -1143,7 +1145,7 @@ const uint8_t kSafepointKind = RawPcDescriptors::kIcCall
CodeBreakpoint::CodeBreakpoint(const Code& code,
- intptr_t token_pos,
+ TokenDescriptor token_pos,
uword pc,
RawPcDescriptors::Kind kind)
: code_(code.raw()),
@@ -1156,7 +1158,7 @@ CodeBreakpoint::CodeBreakpoint(const Code& code,
breakpoint_kind_(kind),
saved_value_(Code::null()) {
ASSERT(!code.IsNull());
- ASSERT(token_pos_ > 0);
+ ASSERT(token_pos_.IsReal());
ASSERT(pc_ != 0);
ASSERT((breakpoint_kind_ & kSafepointKind) != 0);
}
@@ -1647,13 +1649,16 @@ void Debugger::SignalExceptionThrown(const Instance& exc) {
}
-static intptr_t LastTokenOnLine(const TokenStream& tokens, intptr_t pos) {
- TokenStream::Iterator iter(tokens, pos, TokenStream::Iterator::kAllTokens);
+static TokenDescriptor LastTokenOnLine(const TokenStream& tokens,
+ TokenDescriptor pos) {
+ TokenStream::Iterator iter(tokens,
+ pos.value(),
+ TokenStream::Iterator::kAllTokens);
ASSERT(iter.IsValid());
- intptr_t last_pos = pos;
+ TokenDescriptor last_pos = pos;
while ((iter.CurrentTokenKind() != Token::kNEWLINE) &&
- (iter.CurrentTokenKind() != Token::kEOS)) {
- last_pos = iter.CurrentPosition();
+ (iter.CurrentTokenKind() != Token::kEOS)) {
+ last_pos = TokenDescriptor(iter.CurrentPosition());
iter.Advance();
}
return last_pos;
@@ -1716,10 +1721,11 @@ static intptr_t LastTokenOnLine(const TokenStream& tokens, intptr_t pos) {
// algorithm, which would be simpler. I believe that it only needs
// two passes to support the recursive try-the-whole-function case.
// Rewrite this later, once there are more tests in place.
-intptr_t Debugger::ResolveBreakpointPos(const Function& func,
- intptr_t requested_token_pos,
- intptr_t last_token_pos,
- intptr_t requested_column) {
+TokenDescriptor Debugger::ResolveBreakpointPos(
+ const Function& func,
+ TokenDescriptor requested_token_pos,
+ TokenDescriptor last_token_pos,
+ intptr_t requested_column) {
ASSERT(func.HasCode());
ASSERT(!func.HasOptimizedCode());
@@ -1737,12 +1743,12 @@ intptr_t Debugger::ResolveBreakpointPos(const Function& func,
// First pass: find the safe point which is closest to the beginning
// of the given token range.
- intptr_t best_fit_pos = INT_MAX;
+ TokenDescriptor best_fit_pos = TokenDescriptor::kMaxSource;
intptr_t best_column = INT_MAX;
PcDescriptors::Iterator iter(desc, kSafepointKind);
while (iter.MoveNext()) {
- const intptr_t pos = iter.TokenPos();
- if ((!Token::IsReal(pos)) ||
+ const TokenDescriptor pos = iter.TokenPos();
+ if ((!pos.IsReal()) ||
(pos < requested_token_pos) ||
(pos > last_token_pos)) {
// Token is not in the target range.
@@ -1779,16 +1785,16 @@ intptr_t Debugger::ResolveBreakpointPos(const Function& func,
// Second pass (if we found a safe point in the first pass). Find
// the token on the line which is at the best fit column (if column
// was specified) and has the lowest code address.
- if (best_fit_pos != INT_MAX) {
+ if (best_fit_pos != TokenDescriptor::kMaxSource) {
const Script& script = Script::Handle(func.script());
const TokenStream& tokens = TokenStream::Handle(script.tokens());
- const intptr_t begin_pos = best_fit_pos;
- const intptr_t end_of_line_pos = LastTokenOnLine(tokens, begin_pos);
+ const TokenDescriptor begin_pos = best_fit_pos;
+ const TokenDescriptor end_of_line_pos = LastTokenOnLine(tokens, begin_pos);
uword lowest_pc_offset = kUwordMax;
PcDescriptors::Iterator iter(desc, kSafepointKind);
while (iter.MoveNext()) {
- const intptr_t pos = iter.TokenPos();
- if ((!Token::IsReal(pos)) ||
+ const TokenDescriptor pos = iter.TokenPos();
+ if ((!TokenDescriptor(pos).IsReal()) ||
(pos < begin_pos) ||
(pos > end_of_line_pos)) {
// Token is not on same line as best fit.
@@ -1823,13 +1829,13 @@ intptr_t Debugger::ResolveBreakpointPos(const Function& func,
return ResolveBreakpointPos(func, last_token_pos, func.end_token_pos(),
-1 /* no column */);
}
- return Token::kNoSourcePos;
+ return TokenDescriptor::kNoSource;
}
void Debugger::MakeCodeBreakpointAt(const Function& func,
BreakpointLocation* loc) {
- ASSERT(Token::IsReal(loc->token_pos_));
+ ASSERT(TokenDescriptor(loc->token_pos_).IsReal());
ASSERT((loc != NULL) && loc->IsResolved());
ASSERT(!func.HasOptimizedCode());
Code& code = Code::Handle(func.unoptimized_code());
@@ -1867,8 +1873,8 @@ void Debugger::MakeCodeBreakpointAt(const Function& func,
void Debugger::FindCompiledFunctions(const Script& script,
- intptr_t start_pos,
- intptr_t end_pos,
+ TokenDescriptor start_pos,
+ TokenDescriptor end_pos,
GrowableObjectArray* function_list) {
Zone* zone = Thread::Current()->zone();
Class& cls = Class::Handle(zone);
@@ -1952,7 +1958,7 @@ static void SelectBestFit(Function* best_fit, Function* func) {
RawFunction* Debugger::FindBestFit(const Script& script,
- intptr_t token_pos) {
+ TokenDescriptor token_pos) {
Zone* zone = Thread::Current()->zone();
Class& cls = Class::Handle(zone);
Array& functions = Array::Handle(zone);
@@ -2011,8 +2017,8 @@ RawFunction* Debugger::FindBestFit(const Script& script,
BreakpointLocation* Debugger::SetBreakpoint(const Script& script,
- intptr_t token_pos,
- intptr_t last_token_pos,
+ TokenDescriptor token_pos,
+ TokenDescriptor last_token_pos,
intptr_t requested_line,
intptr_t requested_column) {
Function& func = Function::Handle();
@@ -2037,9 +2043,9 @@ BreakpointLocation* Debugger::SetBreakpoint(const Script& script,
// have already been compiled. We can resolve the breakpoint now.
DeoptimizeWorld();
func ^= functions.At(0);
- intptr_t breakpoint_pos =
+ TokenDescriptor breakpoint_pos =
ResolveBreakpointPos(func, token_pos, last_token_pos, requested_column);
- if (breakpoint_pos >= 0) {
+ if (breakpoint_pos >= TokenDescriptor::kMinSource) {
BreakpointLocation* bpt =
GetBreakpointLocation(script, breakpoint_pos, requested_column);
if (bpt != NULL) {
@@ -2242,16 +2248,16 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol(
return NULL;
}
script ^= scripts.At(0);
- intptr_t first_token_idx, last_token_idx;
+ TokenDescriptor first_token_idx, last_token_idx;
script.TokenRangeAtLine(line_number, &first_token_idx, &last_token_idx);
- if (!Token::IsReal(first_token_idx)) {
+ if (!TokenDescriptor(first_token_idx).IsReal()) {
// Script does not contain the given line number.
if (FLAG_verbose_debug) {
OS::Print("Script '%s' does not contain line number %" Pd "\n",
script_url.ToCString(), line_number);
}
return NULL;
- } else if (!Token::IsReal(last_token_idx)) {
+ } else if (!TokenDescriptor(last_token_idx).IsReal()) {
// Line does not contain any tokens.
if (FLAG_verbose_debug) {
OS::Print("No executable code at line %" Pd " in '%s'\n",
@@ -2265,7 +2271,7 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol(
while ((bpt == NULL) && (first_token_idx <= last_token_idx)) {
bpt = SetBreakpoint(script, first_token_idx, last_token_idx,
line_number, column_number);
- first_token_idx++;
+ first_token_idx = TokenDescriptor(first_token_idx.value() + 1);
}
if ((bpt == NULL) && FLAG_verbose_debug) {
OS::Print("No executable code at line %" Pd " in '%s'\n",
@@ -2611,7 +2617,7 @@ void Debugger::SignalPausedEvent(ActivationFrame* top_frame,
event.set_async_continuation(&closure_or_null);
const Script& script = Script::Handle(top_frame->SourceScript());
const TokenStream& tokens = TokenStream::Handle(script.tokens());
- TokenStream::Iterator iter(tokens, top_frame->TokenPos());
+ TokenStream::Iterator iter(tokens, top_frame->TokenPos().value());
if ((iter.CurrentTokenKind() == Token::kIDENT) &&
((iter.CurrentLiteral() == Symbols::Await().raw()) ||
(iter.CurrentLiteral() == Symbols::YieldKw().raw()))) {
@@ -2659,7 +2665,7 @@ RawError* Debugger::DebuggerStepCallback() {
if (!frame->IsDebuggable()) {
return Error::null();
}
- if (!Token::IsDebugPause(frame->TokenPos())) {
+ if (!TokenDescriptor(frame->TokenPos()).IsDebugPause()) {
return Error::null();
}
@@ -2673,7 +2679,7 @@ RawError* Debugger::DebuggerStepCallback() {
String::Handle(frame->SourceUrl()).ToCString(),
frame->LineNumber(),
String::Handle(frame->QualifiedFunctionName()).ToCString(),
- frame->TokenPos());
+ frame->TokenPos().value());
}
ASSERT(stack_trace_ == NULL);
@@ -2758,7 +2764,7 @@ RawError* Debugger::SignalBpReached() {
cbpt->IsInternal() ? "internal" : "user",
String::Handle(cbpt->SourceUrl()).ToCString(),
cbpt->LineNumber(),
- cbpt->token_pos(),
+ cbpt->token_pos().value(),
top_frame->pc());
}
@@ -2837,7 +2843,7 @@ void Debugger::NotifyIsolateCreated() {
// Return innermost closure contained in 'function' that contains
// the given token position.
RawFunction* Debugger::FindInnermostClosure(const Function& function,
- intptr_t token_pos) {
+ TokenDescriptor token_pos) {
Zone* zone = Thread::Current()->zone();
const Script& outer_origin = Script::Handle(zone, function.script());
const GrowableObjectArray& closures =
@@ -2902,18 +2908,18 @@ void Debugger::NotifyCompilation(const Function& func) {
// and set the code breakpoints.
if (!loc->IsResolved()) {
// Resolve source breakpoint in the newly compiled function.
- intptr_t bp_pos =
+ TokenDescriptor bp_pos =
ResolveBreakpointPos(func, loc->token_pos(), loc->end_token_pos(),
loc->requested_column_number());
- if (!Token::IsDebugPause(bp_pos)) {
+ if (!TokenDescriptor(bp_pos).IsDebugPause()) {
if (FLAG_verbose_debug) {
OS::Print("Failed resolving breakpoint for function '%s'\n",
String::Handle(func.name()).ToCString());
}
continue;
}
- intptr_t requested_pos = loc->token_pos();
- intptr_t requested_end_pos = loc->end_token_pos();
+ TokenDescriptor requested_pos = loc->token_pos();
+ TokenDescriptor requested_end_pos = loc->end_token_pos();
loc->SetResolved(func, bp_pos);
Breakpoint* bpt = loc->breakpoints();
while (bpt != NULL) {
@@ -2923,12 +2929,12 @@ void Debugger::NotifyCompilation(const Function& func) {
"function '%s' (requested range %" Pd "-%" Pd ", "
"requested col %" Pd ")\n",
bpt->id(),
- loc->token_pos(),
+ loc->token_pos().value(),
loc->LineNumber(),
loc->ColumnNumber(),
func.ToFullyQualifiedCString(),
- requested_pos,
- requested_end_pos,
+ requested_pos.value(),
+ requested_end_pos.value(),
loc->requested_column_number());
}
SignalBpResolved(bpt);
@@ -2991,10 +2997,9 @@ void Debugger::NotifyDoneLoading() {
intptr_t line_number = matched_loc->requested_line_number();
intptr_t column_number = matched_loc->requested_column_number();
ASSERT(line_number >= 0);
- intptr_t first_token_pos, last_token_pos;
+ TokenDescriptor first_token_pos, last_token_pos;
script.TokenRangeAtLine(line_number, &first_token_pos, &last_token_pos);
- if (!Token::IsDebugPause(first_token_pos) ||
- !Token::IsDebugPause(last_token_pos)) {
+ if (!first_token_pos.IsDebugPause() || !last_token_pos.IsDebugPause()) {
// Script does not contain the given line number or there are no
// tokens on the line. Drop the breakpoint silently.
Breakpoint* bpt = matched_loc->breakpoints();
@@ -3202,7 +3207,7 @@ void Debugger::RemoveInternalBreakpoints() {
BreakpointLocation* Debugger::GetBreakpointLocation(const Script& script,
- intptr_t token_pos,
+ TokenDescriptor token_pos,
intptr_t requested_column) {
BreakpointLocation* bpt = breakpoint_locations_;
while (bpt != NULL) {

Powered by Google App Engine
This is Rietveld 408576698