!825 code revert

Merge pull request !825 from 杨阳/revert
This commit is contained in:
openharmony_ci 2024-08-24 02:50:49 +00:00 committed by Gitee
commit 1a28efcd9e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
7 changed files with 59 additions and 123 deletions

View File

@ -250,23 +250,8 @@ void DebuggerImpl::NotifyPaused(std::optional<JSPtLocation> location, PauseReaso
if (!MatchScripts(scriptFunc, location->GetSourceFile(), ScriptMatchType::URL) ||
extractor == nullptr || !extractor->MatchLineWithOffset(callbackLineFunc, methodId, offset) ||
!extractor->MatchColumnWithOffset(callbackColumnFunc, methodId, offset)) {
LOG_DEBUGGER(WARN) << "NotifyPaused: unknown file " << location->GetSourceFile();
auto jsPandaFile = location->GetJsPandaFile();
if (jsPandaFile == nullptr) {
LOG_DEBUGGER(WARN) << "NotifyPaused: jsPandaFile is nullptr";
return;
}
CString moduleName = jsPandaFile->GetJSPandaFileDesc();
CString recordName = location->GetRecordName();
if (moduleName.empty() || recordName.empty()) {
LOG_DEBUGGER(WARN) << "NotifyPaused: try to reload module after paused failed";
return;
}
hooks_->LoadModule(moduleName, recordName);
detail.url_ = location->GetSourceFile();
detail.line_ = location->GetLine();
detail.column_ = location->GetColumn();
detail.needResetBreakpoint_ = location->GetNeedResetBreakpoint();
LOG_DEBUGGER(ERROR) << "NotifyPaused: unknown file " << location->GetSourceFile();
return;
}
hitBreakpoints.emplace_back(BreakpointDetails::ToString(detail));
}
@ -1072,8 +1057,7 @@ DispatchResponse DebuggerImpl::GetPossibleBreakpoints(const GetPossibleBreakpoin
auto callbackFunc = [](const JSPtLocation &) -> bool {
return true;
};
Global<FunctionRef> funcRef = Global<FunctionRef>(vm_, FunctionRef::Undefined(vm_));
if (extractor->MatchWithLocation(callbackFunc, line, column, url, GetRecordName(url), funcRef)) {
if (extractor->MatchWithLocation(callbackFunc, line, column, url, GetRecordName(url))) {
std::unique_ptr<BreakLocation> location = std::make_unique<BreakLocation>();
location->SetScriptId(start->GetScriptId()).SetLine(line).SetColumn(column);
locations->emplace_back(std::move(location));
@ -1118,13 +1102,8 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa
return true;
};
if (!MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL)) {
LOG_DEBUGGER(WARN) << "RemoveBreakpoint: Unknown url: " << metaData.url_;
JSPtLocation location{metaData.url_, metaData.line_, metaData.column_};
bool res = DebuggerApi::RemoveBreakpointWithNoMatchUrl(jsDebugger_, location);
if (!res) {
return DispatchResponse::Fail("RemoveBreakpointWithNoMatchUrl failed");
}
return DispatchResponse::Ok();
LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: Unknown url: " << metaData.url_;
return DispatchResponse::Fail("Unknown file name.");
}
std::vector<DebugInfoExtractor *> extractors = GetExtractors(metaData.url_);
@ -1138,9 +1117,8 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa
LOG_DEBUGGER(INFO) << "remove breakpoint location: " << location.ToString();
return DebuggerApi::RemoveBreakpoint(jsDebugger_, location);
};
Global<FunctionRef> funcRef = Global<FunctionRef>(vm_, FunctionRef::Undefined(vm_));
if (!extractor->MatchWithLocation(callbackFunc, metaData.line_, metaData.column_,
metaData.url_, GetRecordName(metaData.url_), funcRef)) {
metaData.url_, GetRecordName(metaData.url_))) {
LOG_DEBUGGER(ERROR) << "failed to remove breakpoint location number: "
<< metaData.line_ << ":" << metaData.column_;
}
@ -1157,14 +1135,13 @@ DispatchResponse DebuggerImpl::RemoveBreakpointsByUrl(const RemoveBreakpointsByU
return true;
};
if (!MatchScripts(scriptMatchCallback, url, ScriptMatchType::URL)) {
if (!DebuggerApi::RemoveAllBreakpointsByUrl(jsDebugger_, url, true)) {
return DispatchResponse::Fail("RemoveBreakpointsByUrl failed");
}
} else {
if (!DebuggerApi::RemoveAllBreakpointsByUrl(jsDebugger_, url, false)) {
return DispatchResponse::Fail("RemoveBreakpointsByUrl failed");
}
LOG_DEBUGGER(ERROR) << "RemoveBreakpointByUrl: Unknown url: " << url;
return DispatchResponse::Fail("Unknown url");
}
if (!DebuggerApi::RemoveBreakpointsByUrl(jsDebugger_, url)) {
return DispatchResponse::Fail("RemoveBreakpointByUrl failed");
}
LOG_DEBUGGER(INFO) << "All breakpoints on " << url << " are removed";
return DispatchResponse::Ok();
}
@ -1187,27 +1164,20 @@ DispatchResponse DebuggerImpl::SetAsyncCallStackDepth()
void DebuggerImpl::AddBreakpointDetail(const std::string &url,
int32_t lineNumber,
std::string *outId,
std::vector<std::unique_ptr<Location>> *outLocations,
bool hasScriptId)
std::vector<std::unique_ptr<Location>> *outLocations)
{
if (!hasScriptId) {
ScriptId invalidId = -1;
std::vector<PtScript *> ptScripts = MatchAllScripts(url);
for (auto ptScript : ptScripts) {
ScriptId scriptId = ptScript->GetScriptId();
std::unique_ptr<Location> location = std::make_unique<Location>();
location->SetScriptId(invalidId).SetLine(lineNumber).SetColumn(0);
location->SetScriptId(scriptId).SetLine(lineNumber).SetColumn(0);
outLocations->emplace_back(std::move(location));
} else {
std::vector<PtScript *> ptScripts = MatchAllScripts(url);
for (auto ptScript : ptScripts) {
ScriptId scriptId = ptScript->GetScriptId();
std::unique_ptr<Location> location = std::make_unique<Location>();
location->SetScriptId(scriptId).SetLine(lineNumber).SetColumn(0);
outLocations->emplace_back(std::move(location));
}
}
BreakpointDetails metaData{lineNumber, 0, url};
*outId = BreakpointDetails::ToString(metaData);
}
DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams &params,
std::string *outId,
std::vector<std::unique_ptr<Location>> *outLocations,
@ -1227,14 +1197,8 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams
return true;
};
if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) {
LOG_DEBUGGER(WARN) << "SetBreakpointByUrl: Unknown url: " << url;
JSPtLocation location{url, lineNumber, columnNumber};
bool res = DebuggerApi::SetBreakpointWithNoMatchUrl(jsDebugger_, location);
if (!res) {
return DispatchResponse::Fail("DebuggerImpl SetBreakpointWithNoMatchUrl failed");
}
AddBreakpointDetail(url, lineNumber, outId, outLocations, false);
return DispatchResponse::Ok();
LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: Unknown url: " << url;
return DispatchResponse::Fail("Unknown file name.");
}
std::vector<DebugInfoExtractor *> extractors = GetExtractors(url);
@ -1256,14 +1220,13 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams
}
return DebuggerApi::SetBreakpoint(jsDebugger_, location, condFuncRef, isSmartBreakpoint);
};
Global<FunctionRef> funcRef = Global<FunctionRef>(vm_, FunctionRef::Undefined(vm_));
if (!extractor->MatchWithLocation(callbackFunc, lineNumber, columnNumber, url, GetRecordName(url), funcRef)) {
if (!extractor->MatchWithLocation(callbackFunc, lineNumber, columnNumber, url, GetRecordName(url))) {
LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: "
<< lineNumber << ":" << columnNumber;
return DispatchResponse::Fail("Breakpoint not found.");
}
}
AddBreakpointDetail(url, lineNumber, outId, outLocations, true);
AddBreakpointDetail(url, lineNumber, outId, outLocations);
return DispatchResponse::Ok();
}
@ -1283,31 +1246,26 @@ DispatchResponse DebuggerImpl::GetPossibleAndSetBreakpointByUrl(const GetPossibl
return DispatchResponse::Fail("GetPossibleAndSetBreakpointByUrl: no pennding breakpoint exists");
}
auto breakpointList = params.GetBreakpointsList();
std::vector<JSPtLocation> processedList;
CUnorderedMap<int32_t, ScriptId> scriptIdList;
int32_t index = 0;
for (const auto &breakpoint : *breakpointList) {
ScriptId id = PreProcessBreakpoint(*breakpoint, processedList);
scriptIdList[index++] = id;
}
auto resultList = DebuggerApi::SetBreakpointByList(jsDebugger_, processedList);
index = 0;
ASSERT(resultList.size() == scriptIdList.size());
for (auto const &res : resultList) {
auto breakpoint = processedList.at(index);
GenerateBreakpointOutLocation(scriptIdList[index++], breakpoint.GetSourceFile(),
breakpoint.GetLine(), res, outLocations);
if (!ProcessSingleBreakpoint(*breakpoint, outLocations)) {
std::string invalidBpId = "invalid";
std::unique_ptr<BreakpointReturnInfo> bpInfo = std::make_unique<BreakpointReturnInfo>();
bpInfo->SetId(invalidBpId)
.SetLineNumber(breakpoint->GetLineNumber())
.SetColumnNumber(breakpoint->GetColumnNumber());
outLocations.emplace_back(std::move(bpInfo));
}
}
return DispatchResponse::Ok();
}
ScriptId DebuggerImpl::PreProcessBreakpoint(const BreakpointInfo &breakpoint, std::vector<JSPtLocation> &list)
bool DebuggerImpl::ProcessSingleBreakpoint(const BreakpointInfo &breakpoint,
std::vector<std::unique_ptr<BreakpointReturnInfo>> &outLocations)
{
const std::string &url = breakpoint.GetUrl();
int32_t lineNumber = breakpoint.GetLineNumber();
// it is not support column breakpoint now, so columnNumber is not useful
int32_t columnNumber = -1;
ScriptId noMatchedId = -1;
auto condition = breakpoint.HasCondition() ? breakpoint.GetCondition() : std::optional<std::string> {};
ScriptId scriptId;
@ -1316,14 +1274,14 @@ ScriptId DebuggerImpl::PreProcessBreakpoint(const BreakpointInfo &breakpoint, st
return true;
};
if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) {
LOG_DEBUGGER(INFO) << "DebuggerImpl::PreProcessBreakpoint SUCCESS: URL-NO-MATCH Breakpoint";
JSPtLocation location{url, lineNumber, columnNumber};
list.emplace_back(location);
return noMatchedId;
LOG_DEBUGGER(ERROR) << "GetPossibleAndSetBreakpointByUrl: Unknown url: " << url;
return false;
}
std::vector<DebugInfoExtractor *> extractors = GetExtractors(url);
for (auto extractor : extractors) {
if (extractor == nullptr) {
LOG_DEBUGGER(DEBUG) << "GetPossibleAndSetBreakpointByUrl: extractor is null";
continue;
}
// decode and convert condition to function before doing matchWithLocation
@ -1331,43 +1289,26 @@ ScriptId DebuggerImpl::PreProcessBreakpoint(const BreakpointInfo &breakpoint, st
if (condition.has_value() && !condition.value().empty()) {
funcRef = CheckAndGenerateCondFunc(condition);
if (funcRef->IsUndefined()) {
JSPtLocation location{"invalid", lineNumber, columnNumber};
list.emplace_back(location);
return noMatchedId;
LOG_DEBUGGER(ERROR) << "GetPossibleAndSetBreakpointByUrl: generate function failed";
return false;
}
}
auto matchLocationCbFunc = [&list](const JSPtLocation &location) -> bool {
list.emplace_back(location);
return true;
auto matchLocationCbFunc = [this, &funcRef](const JSPtLocation &location) -> bool {
return DebuggerApi::SetBreakpoint(jsDebugger_, location, funcRef);
};
Global<FunctionRef> globalFuncRef = Global<FunctionRef>(vm_, funcRef);
if (!extractor->MatchWithLocation(matchLocationCbFunc, lineNumber,
columnNumber, url, GetRecordName(url), globalFuncRef)) {
JSPtLocation location{"invalid", lineNumber, columnNumber};
list.emplace_back(location);
return noMatchedId;
} else {
return scriptId;
if (!extractor->MatchWithLocation(matchLocationCbFunc, lineNumber, columnNumber, url, GetRecordName(url))) {
LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: " << lineNumber << ":" << columnNumber;
return false;
}
}
JSPtLocation location{"invalid", lineNumber, columnNumber};
list.emplace_back(location);
return noMatchedId;
}
void DebuggerImpl::GenerateBreakpointOutLocation(ScriptId scriptId, const std::string &url, int32_t line,
bool res, std::vector<std::unique_ptr<BreakpointReturnInfo>> &outLocations)
{
BreakpointDetails bpMetaData {line, 0, url};
BreakpointDetails bpMetaData {lineNumber, 0, url};
std::string outId = BreakpointDetails::ToString(bpMetaData);
std::unique_ptr<BreakpointReturnInfo> bpInfo = std::make_unique<BreakpointReturnInfo>();
if (res) {
std::string outId = BreakpointDetails::ToString(bpMetaData);
bpInfo->SetScriptId(scriptId).SetLineNumber(line).SetColumnNumber(0).SetId(outId);
} else {
std::string invalidBpId = "invalid";
bpInfo->SetScriptId(scriptId).SetLineNumber(line).SetColumnNumber(0).SetId(invalidBpId);
}
bpInfo->SetScriptId(scriptId).SetLineNumber(lineNumber).SetColumnNumber(0).SetId(outId);
outLocations.emplace_back(std::move(bpInfo));
return true;
}
DispatchResponse DebuggerImpl::SetNativeRange(const SetNativeRangeParams &params)

View File

@ -54,7 +54,7 @@ public:
void SetDebuggerState(DebuggerState debuggerState);
void SetNativeOutPause(bool nativeOutPause);
void AddBreakpointDetail(const std::string &url, int32_t lineNumber,
std::string *outId, std::vector<std::unique_ptr<Location>> *outLocations, bool hasScriptId);
std::string *outId, std::vector<std::unique_ptr<Location>> *outLocations);
DispatchResponse ContinueToLocation(const ContinueToLocationParams &params);
DispatchResponse Enable(const EnableParams &params, UniqueDebuggerId *id);
@ -256,12 +256,11 @@ private:
bool IsSkipLine(const JSPtLocation &location);
bool CheckPauseOnException();
bool IsWithinVariableScope(const LocalVariableInfo &localVariableInfo, uint32_t bcOffset);
bool ProcessSingleBreakpoint(const BreakpointInfo &breakpoint,
std::vector<std::unique_ptr<BreakpointReturnInfo>> &outLocations);
bool IsVariableSkipped(const std::string &varName);
Local<FunctionRef> CheckAndGenerateCondFunc(const std::optional<std::string> &condition);
void InitializeExtendedProtocolsList();
void GenerateBreakpointOutLocation(ScriptId scriptId, const std::string &url, int32_t line,
bool res, std::vector<std::unique_ptr<BreakpointReturnInfo>> &outLocations);
ScriptId PreProcessBreakpoint(const BreakpointInfo &breakpoint, std::vector<JSPtLocation> &list);
const std::unordered_set<std::string> &GetRecordName(const std::string &url)
{

View File

@ -81,7 +81,6 @@ struct BreakpointDetails {
int32_t line_ {0};
int32_t column_ {0};
std::string url_ {};
bool needResetBreakpoint_ {false};
};
// Debugger.CallFrameId

View File

@ -49,7 +49,6 @@ public:
JSNApi::StartDebugger(instance, debugOption);
if (instance->GetJsDebuggerManager() != nullptr) {
instance->GetJsDebuggerManager()->DisableObjectHashDisplay();
instance->GetJsDebuggerManager()->DisableBreakpointSync();
}
}

View File

@ -49,7 +49,6 @@ public:
JSNApi::StartDebugger(instance, debugOption);
if (instance->GetJsDebuggerManager() != nullptr) {
instance->GetJsDebuggerManager()->DisableObjectHashDisplay();
instance->GetJsDebuggerManager()->DisableBreakpointSync();
}
}

View File

@ -547,7 +547,8 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpoint__003)
DispatchRequest request(msg);
dispatcherImpl->Dispatch(request);
EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
EXPECT_STREQ(outStrForCallbackCheck.c_str(),
R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
if (protocolChannel) {
delete protocolChannel;
protocolChannel = nullptr;
@ -603,7 +604,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_RemoveBreakpointsByUrl__002)
DispatchRequest request(msg);
dispatcherImpl->Dispatch(request);
EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{}})");
EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown url"}})");
if (protocolChannel) {
delete protocolChannel;
protocolChannel = nullptr;
@ -755,8 +756,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_SetBreakpointByUrl__002)
DispatchRequest request(msg);
dispatcherImpl->Dispatch(request);
EXPECT_STREQ(outStrForCallbackCheck.c_str(),
R"({"id":0,"result":{"code":1,"message":"DebuggerImpl SetBreakpointWithNoMatchUrl failed"}})");
EXPECT_STREQ(outStrForCallbackCheck.c_str(), R"({"id":0,"result":{"code":1,"message":"Unknown file name."}})");
if (protocolChannel) {
delete protocolChannel;
protocolChannel = nullptr;
@ -1229,7 +1229,7 @@ HWTEST_F_L0(DebuggerImplTest, Dispatcher_Dispatch_GetPossibleAndSetBreakpoint__0
dispatcherImpl->Dispatch(request);
EXPECT_STREQ(outStrForCallbackCheck.c_str(),
R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":0,"id":"invalid","scriptId":-1}]}})");
R"({"id":0,"result":{"locations":[{"lineNumber":3,"columnNumber":20,"id":"invalid","scriptId":0}]}})");
if (protocolChannel) {
delete protocolChannel;
protocolChannel = nullptr;

View File

@ -36,8 +36,7 @@ std::pair<EntityId, uint32_t> TestExtractor::GetBreakpointAddress(const SourceLo
return true;
};
std::unordered_set<std::string> recordName {};
Global<FunctionRef> funcRef;
MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName, funcRef);
MatchWithLocation(callbackFunc, sourceLocation.line, sourceLocation.column, "", recordName);
return {retId, retOffset};
}