diff --git a/lua_probject/base_project/Game/View/Family/FamilAllRank.lua b/lua_probject/base_project/Game/View/Family/FamilAllRank.lua index 46291f3f..0b13e499 100644 --- a/lua_probject/base_project/Game/View/Family/FamilAllRank.lua +++ b/lua_probject/base_project/Game/View/Family/FamilAllRank.lua @@ -86,6 +86,13 @@ function M:InitTime() return serverDayValues, serverDayItems end +function M:ShouRanks() + self._lastTpe = self._father.familyType.selectedIndex + self._father.familyType.selectedIndex = 0 + self._view.visible = true + self:SearchRank() +end + function M:RoundListRenderer(index, obj) local rankTable = self.roundRanks obj:GetChild('text_rank').text = index @@ -116,7 +123,7 @@ end function M:SearchRank() local fgCtr = ControllerManager.GetController(NewGroupController) local begin_time = math.min(self.leftTimes, self.rightTimes) - local end_time = math.max(self.leftTimes, self.rightTimes) + local end_time = math.max(self.leftTimes, self.rightTimes) + 86399 self:ClearingTable() self:RecursionSearchRank(fgCtr, 0, begin_time, end_time) end diff --git a/lua_probject/base_project/Game/View/Family/FamilyNumberRecord.lua b/lua_probject/base_project/Game/View/Family/FamilyNumberRecord.lua index aa1f8948..060a3ee7 100644 --- a/lua_probject/base_project/Game/View/Family/FamilyNumberRecord.lua +++ b/lua_probject/base_project/Game/View/Family/FamilyNumberRecord.lua @@ -1,5 +1,3 @@ -local FamilyChooseTimeView = import(".FamilyChooseTimeView") - local FamilyNumberRecord = { military = { size = 0, list = {} }, rankNumber = {}, @@ -8,112 +6,103 @@ local FamilyNumberRecord = { local M = FamilyNumberRecord function FamilyNumberRecord.New(root) - setmetatable(M, { __index = root }) local self = setmetatable({}, { __index = M }) - -- print("lingmengFamilyNumberRecord") - -- for key, value in pairs(self._group) do - -- if type(value) == "table" then - -- print(key) - -- pt(value) - -- else - -- print(key .. ":" .. tostring(value)) - -- end - -- end - local group_id = self._group.id + self._father = root + self._lastTpe = root.familyType.selectedIndex + self.group_id = root._group.id + root.familyType.selectedIndex = 0 + local comp_numberRecord = UIPackage.CreateObjectFromURL("ui://Family/comp_numberRecord") + root._view:AddChild(comp_numberRecord) + comp_numberRecord.width = root._view.width + comp_numberRecord.height = root._view.height + comp_numberRecord:Center() + self._view = comp_numberRecord + + local group_id = self.group_id local MJScore = 0 local PKScore = 0 local fgCtr = ControllerManager.GetController(NewGroupController) - local comp_gameTypeList = self._view:GetChild('comp_gameTypeList'):GetChild('n0') local input_IDSerach = self._view:GetChild('input_numberID') - local text_recordGameType = self._view:GetChild('text_recordGameType') - local text_recordSortType = self._view:GetChild('text_recordSortType') local text_allRound = self._view:GetChild('text_allRound') local text_winNum = self._view:GetChild('text_winNum') local text_useDiamond = self._view:GetChild('text_useDiamond') - local btn_chooseTimeBegin = self._view:GetChild('btn_chooseTimeBegin') - local btn_chooseTimeEnd = self._view:GetChild('btn_chooseTimeEnd') local text_score_poker = self._view:GetChild('text_score_poker') local text_score_majiang = self._view:GetChild('text_score_majiang') - local ctr_numberRecordRank = self._view:GetController('numberRecordRank') - local ctr_chooseTime = self._view:GetController('showChooseTime') + local box_type = self._view:GetChild('combBox_type') + local ctr_day = self._view:GetController('day') + local ctr_sort = self._view:GetController('sort') + local ctr_limitDay = self._view:GetController('limitDay') - self.familyType.selectedIndex = 5 - self.familyChooseTimeView = FamilyChooseTimeView.New(self, self._view:GetChild('comp_chooseTime')) + -- self.familyType.selectedIndex = 5 self._viewList_numberRankRead = self._view:GetChild('comp_numberRecordByGameTypelooked'):GetChild('n3') self._viewList_numberRankUnRead = self._view:GetChild('comp_numberRecordByGameType'):GetChild('n3') self._viewList_numverRecord = self._view:GetChild('list_numverRecord') self._viewlist_numberRecordDetail = self._view:GetChild('list_numberRecordDetail') self._viewText_titleRecord = self._view:GetChild('text_titleRecord') + self.ctr_numberRecord = self._view:GetController('page') + self._cte_noPeople = self._view:GetController('noPeople') - self.ctr_numberRecord = self._view:GetController('numberRecord') + self._text_groupTitle = string.format("%s(%s)", root._group.name, group_id) - self._text_groupTitle = string.format("%s(%s)", self._group.name, group_id) - btn_chooseTimeBegin.text = os.date('%Y-%m-%d', os.time()) - btn_chooseTimeEnd.text = os.date('%Y-%m-%d', os.time()) + box_type.items, box_type.values = self:InitBoxType() text_score_majiang.text = 0 - MJScore text_score_poker.text = 0 - PKScore self._viewText_titleRecord.text = string.format("%s 成员记录", self._text_groupTitle) - self._view:GetChild('text_residueDiamond').text = self._group.diamo - self._view:GetChild('text_timeRecord').text = os.date('%Y-%m-%d %H:%M', os.time()) + self._view:GetChild('text_residueDiamond').text = root._group.diamo + self._view:GetChild('text_timeRecord').text = os.date('%Y-%m-%d %H:%M:%S', os.time()) + self:InitTimeAndSord() self:NumverRecordRenderer(group_id) self:NumverRankRenderer(group_id) - self:GameTypeListRenderer(comp_gameTypeList) self:NumberRecordDetailRender() - btn_chooseTimeBegin.onClick:Set(function() - ctr_chooseTime.selectedIndex = 1 - self.familyChooseTimeView:ChooseTime(0, function(type, text1, text2) - ctr_chooseTime.selectedIndex = 0 - if type == 0 then - btn_chooseTimeBegin.text = text1 - else - btn_chooseTimeBegin.text = text1 - btn_chooseTimeEnd.text = text2 - end - end) + ctr_day.onChanged:Set(function(context) + local timeTable = os.date("*t", os.time()) + timeTable.hour = 0 + timeTable.min = 0 + timeTable.sec = 0 + local index = context.sender.selectedIndex + self._data_leftTime = os.time(timeTable) - index * 86400 + self._data_rightTime = os.time(timeTable) - index * 86400 + 86399 + self:OnClickSortType() end) - btn_chooseTimeEnd.onClick:Set(function() - ctr_chooseTime.selectedIndex = 1 - self.familyChooseTimeView:ChooseTime(1, function(type, text1, text2) - ctr_chooseTime.selectedIndex = 0 - if type == 0 then - btn_chooseTimeEnd.text = text1 - else - btn_chooseTimeBegin.text = text1 - btn_chooseTimeEnd.text = text2 - end - end) + + ctr_sort.onChanged:Set(function() + local index = context.sender.selectedIndex + self._data_sortType = index + self:OnClickSortType() end) - comp_gameTypeList.onClickItem:Set(function(context) - input_IDSerach.text = "" - self:OnClickSortType(group_id, context.data.data.id) - ctr_numberRecordRank.selectedIndex = 0 - text_recordGameType.text = context.data.title + + box_type.onChanged:Set(function() + -- self._data_seletedType = box_type.value + self._data_seletedType = 0 + self:OnClickSortType() end) - self.btn_close.onClick:Set(function() - if self.ctr_numberRecord.selectedIndex > 0 then - self.ctr_numberRecord.selectedIndex = self.ctr_numberRecord.selectedIndex - 1 - else - self:InitCloseClick() - self.familyType.selectedIndex = 1 - end + + ctr_limitDay.onChanged:Set(function() + --写限制分数 end) + self.ctr_numberRecord.onChanged:Set(function() if self.ctr_numberRecord.selectedIndex == 0 then self._viewText_titleRecord.text = string.format("%s 成员记录", self._text_groupTitle) - self._view:GetChild('text_timeRecord').text = os.date('%Y-%m-%d %H:%M', os.time()) + self._view:GetChild('text_timeRecord').text = os.date('%Y-%m-%d %H:%M:%S', os.time()) elseif self.ctr_numberRecord.selectedIndex == 1 then self._viewText_titleRecord.text = string.format("%s 个人记录", self._text_groupTitle) - self._view:GetChild('text_numberRecordTime').text = os.date('%Y-%m-%d %H:%M', os.time()) + self._view:GetChild('text_numberRecordTime').text = os.date('%Y-%m-%d %H:%M:%S', os.time()) elseif self.ctr_numberRecord.selectedIndex == 2 then self._viewText_titleRecord.text = string.format("%s %s", self._text_groupTitle, self._flag_unReadDetail and "未读详情" or "已读详情") end end) + self._view:GetChild('btn_close').onClick:Set(function() + root.familyType.selectedIndex = self._lastTpe + self._lastTpe = nil + self._view.visible = false + end) self._view:GetChild('btn_clearInput').onClick:Set(function() input_IDSerach.text = "" end) @@ -129,6 +118,7 @@ function FamilyNumberRecord.New(root) else self.showRank = tempRank self._viewList_numverRecord.numItems = #self.showRank + self._cte_noPeople.selectedIndex = #self.showRank == 0 end end) self._view:GetChild('btn_changeMJScore').onClick:Set(function() @@ -179,54 +169,46 @@ function FamilyNumberRecord.New(root) self._flag_allChooseReverse = self.records[self.gameTypeNum][self.readStatusNum].childNum self._viewlist_numberRecordDetail:RefreshVirtualList() end) - self._view:GetChild('comp_sortTypeList'):GetChild('n0').onClickItem:Set(function(context) - input_IDSerach.text = "" - local sortType = tonumber(context.data.text) - self:OnClickSortType(group_id, 0, sortType) - ctr_numberRecordRank.selectedIndex = 0 - text_recordSortType.text = sortType == 1 and "正数榜" or "负数榜" - end) - self:OnClickSortType(group_id) + self:OnClickSortType() - fgCtr:FG_GetConsumeStat(group_id, self.familyChooseTimeView:GetBeginTime(), self.familyChooseTimeView:GetEndTime(), - function(res) - pt(res) - if res.ReturnCode ~= 0 then - ViewUtil.ShowOneChooose("获取总信息失败" .. res.ReturnCode) - else - MJScore = tonumber(res.Data.mj_score) - PKScore = tonumber(res.Data.pk_score) - text_score_majiang.text = 0 - MJScore - text_score_poker.text = 0 - PKScore - end - end) + -- fgCtr:FG_GetConsumeStat(group_id, self.familyChooseTimeView:GetBeginTime(), self.familyChooseTimeView:GetEndTime(), + -- function(res) + -- pt(res) + -- if res.ReturnCode ~= 0 then + -- ViewUtil.ShowOneChooose("获取总信息失败" .. res.ReturnCode) + -- else + -- MJScore = tonumber(res.Data.mj_score) + -- PKScore = tonumber(res.Data.pk_score) + -- text_score_majiang.text = 0 - MJScore + -- text_score_poker.text = 0 - PKScore + -- end + -- end) return self end -function M:GameTypeListRenderer(comp_gameTypeList) - local games = DataManager.SelfUser.games +function M:InitBoxType() + local items = { "扑克", "麻将" } + local values = { "1", "2" } - comp_gameTypeList:SetVirtual() - comp_gameTypeList.itemRenderer = function(index, obj) - if index == 0 then - obj.title = "麻将" - obj.data = {} - obj.data.index = index - obj.data.id = -1 - elseif index == 1 then - obj.title = "扑克" - obj.data = {} - obj.data.index = index - obj.data.id = -2 - else - obj.title = games[index - 1].name - obj.data = {} - obj.data.index = index - obj.data.id = games[index - 1].game_id - end + local games = DataManager.SelfUser.games + for i = 1, #games do + table.insert(items, games[i].name) + table.insert(values, tostring(games[i].game_id)) end - comp_gameTypeList.numItems = #games + 2 + + self._data_seletedType = 0 + return items, values +end + +function M:InitTimeAndSord() + local timeTable = os.date("*t", os.time()) + timeTable.hour = 0 + timeTable.min = 0 + timeTable.sec = 0 + self._data_leftTime = os.time(timeTable) + self._data_rightTime = os.time(timeTable) + 86399 + self._data_sortType = 0 end function M:NumverRecordRenderer() @@ -329,7 +311,7 @@ function M:NumverRankRenderer(groupId) self.ctr_numberRecord.selectedIndex = 1 self:OnClickNumberRank(groupId, info.uid, info.round) self._view:GetChild('text_numberRecordName').text = info.nick - self._view:GetChild('text_numberRecordID').text = info.uid + self._view:GetChild('text_numberRecordID').text = string.format("ID:%s", info.uid) ImageLoad.Load(info.portrait, self._view:GetChild('btn_numberRecordHead')._iconObject) self.rankNumber.uid = info.uid self.rankNumber.round = info.round @@ -337,31 +319,36 @@ function M:NumverRankRenderer(groupId) end end -function M:OnClickSortType(groupId, pid, sortType) +function M:OnClickSortType() print("lingmengOnClickSortType") + self.rank = {} local fgCtr = ControllerManager.GetController(NewGroupController) - local numberRecordList = self._viewList_numverRecord - fgCtr:FG_GetMemberRank(groupId, 0, 0, 10, self.familyChooseTimeView:GetBeginTime(), - self.familyChooseTimeView:GetEndTime(), sortType, function(res) - pt(res) - if res.ReturnCode ~= 0 then - ViewUtil.ShowOneChooose("获取排行榜失败" .. res.ReturnCode) - else - self.rank = res.Data.ranks - self.showRank = self.rank - local round = 0 - local win = 0 - local cost = 0 - for i = 1, #self.rank do + self:RecursionGetNumberRank(fgCtr, 0, 0, 0, 0) +end + +function M:RecursionGetNumberRank(fgCtr, index, round, win, cost) + fgCtr:FG_GetMemberRank(self.group_id, 0, index * 2, 2, self._data_leftTime, self._data_rightTime, nil, function(res) + if res.ReturnCode ~= 0 then + ViewUtil.ErrorTip(res.ReturnCode, "获取排行榜失败") + return + else + local info = res.Data + if info.ranks and #info.ranks > 0 then + for i = 1, #info.ranks do + table.insert(self.rank, info.ranks[i]) round = round + self.rank[i].round win = win + self.rank[i].win end + self:RecursionGetNumberRank(fgCtr, index + 1, round, win, cost) + else round = math.floor(round / 2) self._view:GetChild('text_allRound').text = round self._view:GetChild('text_winNum').text = win - numberRecordList.numItems = #self.showRank + self.showRank = self.rank + self._viewList_numverRecord.numItems = #self.showRank end - end) + end + end) end function M:OnClickNumberRank(groupId, uid, round) @@ -369,8 +356,7 @@ function M:OnClickNumberRank(groupId, uid, round) local fgCtr = ControllerManager.GetController(NewGroupController) local numberRankListRead = self._viewList_numberRankRead local numberRankListUnRead = self._viewList_numberRankUnRead - fgCtr:FG_GetGroupRecordSpe(groupId, GetPlatform(), uid, 0, 0, round, self.familyChooseTimeView:GetBeginTime(), - self.familyChooseTimeView:GetEndTime(), 3, + fgCtr:FG_GetGroupRecordSpe(groupId, GetPlatform(), uid, 0, 0, round, self._data_leftTime, self._data_rightTime, 3, function(res) pt(res) if res.ReturnCode ~= 0 then @@ -402,6 +388,10 @@ function M:OnClickNumberRank(groupId, uid, round) end) end +function M:RecursionGetNumberRecord() + +end + function M:ResetRecords() self.records = {} for i = 1, 2 do diff --git a/lua_probject/base_project/Game/View/Family/FamilyRecord.lua b/lua_probject/base_project/Game/View/Family/FamilyRecord.lua index 8c9592f0..bbf14822 100644 --- a/lua_probject/base_project/Game/View/Family/FamilyRecord.lua +++ b/lua_probject/base_project/Game/View/Family/FamilyRecord.lua @@ -1,34 +1,25 @@ -local FamilyRecord = {} +local FamilAllRank = {} -function FamilyRecord:TryShow(r) - if not self._view then - self:Init() - root = r - end +local M = FamilAllRank - self:Show() +function FamilAllRank.New(root, groupId) + local self = setmetatable({}, { __index = M }) + self._father = root + self.group_id = groupId + self:init() + return self end -function FamilyRecord:Show() - BaseView.Show(self) +function M:init() + local root = self._father + self._lastTpe = root.familyType.selectedIndex + root.familyType.selectedIndex = 0 + local com_Record = UIPackage.CreateObjectFromURL("ui://Family/com_Record") + root._view:AddChild(com_Record) + com_Record.width = root._view.width + com_Record.height = root._view.height + com_Record:Center() + self._view = com_Record end - -function FamilyRecord:Init() - setmetatable(FamilyRecord, {__index = BaseView}) - - self:InitView("ui://Family/com_Record") - - local loader_test = self._view:GetChild("loader_test") - - local btn_close = self._view:GetChild("btn_close") - - btn_close.onClick:Set(function() - self:Close() - end) - - ImageLoad.Load() - --self -end - -return FamilyRecord \ No newline at end of file +return M diff --git a/lua_probject/base_project/Game/View/FamilyView.lua b/lua_probject/base_project/Game/View/FamilyView.lua index d5d8f55a..4804e994 100644 --- a/lua_probject/base_project/Game/View/FamilyView.lua +++ b/lua_probject/base_project/Game/View/FamilyView.lua @@ -3,16 +3,16 @@ local CreatePlayView = import('.Family.CreatePlayView') local GroupGameSettingView = import(".NewGroup.MngView.GroupGameSettingView_jaingxi") local LobbyShopView = import(".Lobby.LobbyShopView") local FamilAllRank = import(".Family.FamilAllRank") +local FamilyNumberRecord = import(".Family.FamilyNumberRecord") +local FamilyRecord = import(".Family.FamilyRecord") ---无窗口 local FamilyAllNumbers = import(".Family.FamilyAllNumbers") -local FamilyNumberRecord = import(".Family.FamilyNumberRecord") local FamilyAuditNumber = import(".Family.FamilyAuditNumber") local FamilyJoinAndCreate = import(".Family.FamilyJoinAndCreate") local FamilyEventView = import(".Family.FamilyEventView") local FamilyBanDesk = import(".Family.FamilyBanDesk") local FamilyMyFamily = import(".Family.FamilyMyFamily") -local FamilyRecord = import(".Family.FamilyRecord") local FamilyRoomCard = import(".Family.FamilyRoomCard") --- FamilyView = {} @@ -90,7 +90,11 @@ function M:ShareWx() end function M:FamilyRecord() - FamilyRecord:TryShow(self) + if not self._ViewChild_Record or not self._ViewChild_Record.ShouRanks then + self._ViewChild_Record = FamilyRecord.New(self, self._group.id) + return + end + self._ViewChild_Record:ShouRanks() end function M:CreateFamily(frist) @@ -134,9 +138,11 @@ function M:ShowShop() end function M:ShowAllRank() - if not self._ViewChild_AllRank then + if not self._ViewChild_AllRank or not self._ViewChild_AllRank.ShouRanks then self._ViewChild_AllRank = FamilAllRank.New(self, self._group.id) + return end + self._ViewChild_AllRank:ShouRanks() end function M:MoreBtn() diff --git a/lua_probject/base_project/LuaDebug.lua b/lua_probject/base_project/LuaDebug.lua index f7481d24..26abf930 100644 --- a/lua_probject/base_project/LuaDebug.lua +++ b/lua_probject/base_project/LuaDebug.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile =nil -xpcall(function() +local debugger_reLoadFile = nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end,function() +end, function() debugger_reLoadFile = function() print("未实现代码重载") end end) local debugger_stackInfo = nil @@ -21,27 +21,27 @@ local setfenv = setfenv if (not setfenv) then setfenv = function(fn, env) - local i = 1 - while true do - local name = debug.getupvalue(fn, i) - if name == "_ENV" then - debug.upvaluejoin( - fn, - i, - (function() - return env - end), - 1 - ) - break - elseif not name then - break - end + local i = 1 + while true do + local name = debug.getupvalue(fn, i) + if name == "_ENV" then + debug.upvaluejoin( + fn, + i, + (function() + return env + end), + 1 + ) + break + elseif not name then + break + end - i = i + 1 + i = i + 1 + end + return fn end - return fn - end end local ZZBase64 = {} local LuaDebugTool_ = nil @@ -154,50 +154,50 @@ local function createSocket() sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) + end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 + end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -205,63 +205,63 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if length <= 0 then - return nil + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err + }, + { + __call = function() + if length <= 0 then + return nil + end + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err + end + length = length - string.len(chunk) + return chunk end - length = length - string.len(chunk) - return chunk - end - } - ) - end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if done then - return nil + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err + }, + { + __call = function() + if done then + return nil + end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err + end end - end - } - ) - end + } + ) + end sourcet["default"] = sourcet["until-closed"] @@ -278,7 +278,7 @@ local function createJson() ----------------------------------------------------------------------------- -- Module declaration ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local json = {} -- Public namespace local json_private = {} -- Private namespace -- Public constants @@ -392,6 +392,7 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end + ----------------------------------------------------------------------------- -- Internal, PRIVATE functions. -- Following a Python-like convention, I have prefixed all these 'PRIVATE' @@ -449,8 +450,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = {["true"] = true, ["false"] = false, ["null"] = nil} - local constNames = {"true", "false", "null"} + local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } + local constNames = { "true", "false", "null" } for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -599,7 +600,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -675,13 +676,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -704,7 +705,7 @@ local breakInfoSocket = nil local json = createJson() local LuaDebugger = { fileMaps = {}, - Run = true, --表示正常运行只检测断点 + Run = true, --表示正常运行只检测断点 StepIn = false, StepInLevel = 0, StepNext = false, @@ -776,17 +777,17 @@ function print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 1} + data = { msg = ZZBase64.encode(str), type = 1 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") @@ -800,46 +801,48 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 2} + data = { msg = ZZBase64.encode(str), type = 2 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end + function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 3} + data = { msg = ZZBase64.encode(str), type = 3 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end + --@endregion --@region 辅助方法 @@ -876,7 +879,7 @@ local function debugger_getFilePathInfo(file) file = file:gsub("/.\\", "/") file = file:gsub("\\", "/") file = file:gsub("//", "/") - + if file:find("@") == 1 then file = file:sub(2) @@ -1031,25 +1034,23 @@ local function debugger_dump(value, desciption, nesting) end --@endregion local function debugger_valueToString(v) - local vtype = type(v) + local vtype = type(v) local vstr = nil if (vtype == "userdata") then if (LuaDebugger.isFoxGloryProject) then - - return "userdata",vtype - + return "userdata", vtype else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() + xpcall(function() value = tostring(v) - end,function() + end, function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string" ) then + elseif (vtype == "number" or vtype == "string") then return v, vtype else return tostring(v), vtype @@ -1057,12 +1058,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr,nameType = debugger_valueToString(name) - if(valueStr == nil) then + local nameStr, nameType = debugger_valueToString(name) + if (valueStr == nil) then valueStr = valueType end local valueInfo = { - name =nameStr, + name = nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1100,64 +1101,64 @@ local function debugger_getvalue(f) i = i + 1 end - return {locals = locals, ups = ups} + return { locals = locals, ups = ups } end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end end - if (file == "=[C]") then - isadd = false + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break end end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break - end - end - - local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } - LuaDebugger.currentTempFunc = data.funcs[1] - return data -end + + local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } + LuaDebugger.currentTempFunc = data.funcs[1] + return data + end --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 @@ -1172,32 +1173,32 @@ local function debugger_receiveDebugBreakInfo() end if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if(LuaDebugger.isLaunch and status == "closed") then - os.exit() + if (LuaDebugger.isLaunch and status == "closed") then + os.exit() end if (msg) then local netData = json.decode(msg) if netData.event == LuaDebugger.event.S2C_SetBreakPoints then debugger_setBreak(netData.data) elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) LuaDebugger.reLoadFileBody.script = nil debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end + ) + end end end end @@ -1221,76 +1222,76 @@ local function splitFilePath(path) end debugger_setBreak = function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end end end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil end end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false end -end local function debugger_checkFileIsBreak(fileName) return LuaDebugger.breakInfos[fileName] end @@ -1322,31 +1323,30 @@ function debugger_conditionStr(condition, vars, callBack) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. condition) setfenv(fun, currentTabble) return fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end + --执行lua字符串 debugger_exeLuaString = function() - local function loadScript() - local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = {_G = _G} + local currentTabble = { _G = _G } local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1359,8 +1359,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, {__index = _G}) - + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1370,54 +1370,51 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event + .C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true - end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key,keyType,value) - if(keyType == -1) then +local function debugger_getTablekey(key, keyType, value) + if (keyType == -1) then return key - elseif(keyType == 1) then + elseif (keyType == 1) then return tonumber(key) - elseif(keyType == 2) then + elseif (keyType == 2) then local valueKey = nil - for k,v in pairs(value) do + for k, v in pairs(value) do local nameType = type(k) - if(nameType == "userdata" or nameType == "table") then + if (nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if(key == valueKey) then + if (key == valueKey) then return k end break end end end - end end local function debugger_setVarValue(server, data) - local newValue = nil - local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1432,7 +1429,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if(firstKeyName == name) then + if (firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1446,11 +1443,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if(localValueChangeIndex == -1 and firstKeyName == name) then + if (localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1462,9 +1459,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end ---@endregion - local vars = {locals = locals, ups = ups} - + --@endregion + local vars = { locals = locals, ups = ups } + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1480,58 +1477,56 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if(keyLength == 1) then - if(localValueChangeIndex ~= -1) then - + + if (keyLength == 1) then + if (localValueChangeIndex ~= -1) then debug.setlocal(level, localValueChangeIndex, newValue) - elseif(upValueFun ~= nil) then - debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) + elseif (upValueFun ~= nil) then + debug.setupvalue(upValueFun, upValueChangeIndex, newValue) else --全局变量查找 - if(_G[firstKeyName]) then + if (_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if(not oldValue) then - if(_G[firstKeyName]) then + if (not oldValue) then + if (_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i=2,keyLength-1 do - if(tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] + for i = 2, keyLength - 1 do + if (tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] end end - if(tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue + if (tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - end --@endregion @@ -1541,44 +1536,44 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server,LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - print("设置变量", error) - end - ) - elseif(LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("执行代码", error) - end - ) - elseif(LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("重新加载文件", error) - end - ) + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server, LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif (LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif (LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) + end end -end - + local function getSource(source) @@ -1598,7 +1593,7 @@ local function debugger_GeVarInfoBytUserData(server, var) local fileds = LuaDebugTool.getUserDataInfo(var) local varInfos = {} - + --c# vars for i = 1, fileds.Count do @@ -1619,18 +1614,18 @@ end local function debugger_getValueByScript(value, script) local val = nil local status, - msg = + msg = xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - print(error, "====>") - val = nil - end - ) + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) return val end @@ -1735,7 +1730,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1863,9 +1858,9 @@ local function debugger_sendTableValues(value, server, variablesReference, debug if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1894,7 +1889,6 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end - end else m = getmetatable(value) @@ -1944,7 +1938,6 @@ local function debugger_getBreakVar(body, server) if (value) then local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) else if (valueType == "function") then @@ -2018,25 +2011,24 @@ local function debugger_loop(server) while true do local line, status = server:receive() if (status == "closed") then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end end if (line) then local netData = json.decode(line) local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end elseif event == LuaDebugger.event.S2C_SetBreakPoints then --设置断点信息 local function setB() @@ -2137,8 +2129,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2156,29 +2148,26 @@ local function debugger_loop(server) end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - - if(not LuaDebugger.isHook) then + if (not LuaDebugger.isHook) then return end - - if(LuaDebugger.Run) then - if(event == "line") then + + if (LuaDebugger.Run) then + if (event == "line") then local isCheck = false for k, breakInfo in pairs(LuaDebugger.breakInfos) do - for bk, linesInfo in pairs(breakInfo) do - - if(linesInfo.lines and linesInfo.lines[line]) then + if (linesInfo.lines and linesInfo.lines[line]) then isCheck = true break end end - if(isCheck) then - break - end + if (isCheck) then + break + end end - if(not isCheck) then + if (not isCheck) then return end else @@ -2200,8 +2189,8 @@ debug_hook = function(event, line) else if (LuaDebugger.currentDebuggerData.funcs[2] == tempFun) then local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - --挂起等待调试器作出反应 - + --挂起等待调试器作出反应 + _resume(coro_debugger, data) checkSetVar() end @@ -2254,12 +2243,11 @@ debug_hook = function(event, line) LuaDebugger.currentFileName = file end file = LuaDebugger.currentFileName - + --判断断点 local breakInfo = LuaDebugger.breakInfos[file] local breakData = nil if (breakInfo) then - local ischeck = false for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines @@ -2268,7 +2256,7 @@ debug_hook = function(event, line) break end end - + if (ischeck) then --并且在断点中 local info = stepInfo @@ -2276,7 +2264,7 @@ debug_hook = function(event, line) info = getinfo(2) end local hitPathNames = splitFilePath(LuaDebugger.currentLineFile) - + local hitCounts = {} local debugHitCounts = nil for k, lineInfo in pairs(breakInfo) do @@ -2288,7 +2276,7 @@ debug_hook = function(event, line) --判断路径 hitCounts[k] = 0 local hitPathNamesCount = #hitPathNames - + local pathNamesCount = #pathNames local checkCount = 0; while (true) do @@ -2299,13 +2287,13 @@ debug_hook = function(event, line) end pathNamesCount = pathNamesCount - 1 hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount+1 - + checkCount = checkCount + 1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then break end end - if(checkCount>0) then + if (checkCount > 0) then break; end else @@ -2354,8 +2342,8 @@ debug_hook = function(event, line) local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) -- 挂起等待调试器作出反应 if (data) then - LuaDebugger.currentTempFunc = data.funcs[1] - + LuaDebugger.currentTempFunc = data.funcs[1] + _resume(coro_debugger, data) checkSetVar() return @@ -2384,8 +2372,8 @@ end local function debugger_xpcall() --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if(data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if (data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end --挂起等待调试器作出反应 _resume(coro_debugger, data) @@ -2438,7 +2426,7 @@ local function start() print(msg) end end - _resume(coro_debugger, server) + _resume(coro_debugger, server) end end end @@ -2478,25 +2466,25 @@ ZZBase64.__code = { 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; ZZBase64.__decode = {} -for k,v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v,1)] = k - 1 +for k, v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v, 1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i ) + local a = string.byte(text, i) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4-j) * 6))) + local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2516,7 +2504,7 @@ function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 local tmp1 = math.floor(num / 4096) --rShift 12 @@ -2533,13 +2521,13 @@ function ZZBase64.__left2(res, index, text, len) res[index + 3] = "=" end -function ZZBase64.__left1(res, index,text, len) +function ZZBase64.__left1(res, index, text, len) local num = string.byte(text, len + 1) num = num * 16 local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index ] = ZZBase64.__code[curPos] + res[index] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] @@ -2562,11 +2550,11 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i =1, len, 4 do - local a = decode[string.byte(text,i )] - local b = decode[string.byte(text,i + 1)] - local c = decode[string.byte(text,i + 2)] - local d = decode[string.byte(text,i + 3)] + for i = 1, len, 4 do + local a = decode[string.byte(text, i)] + local b = decode[string.byte(text, i + 1)] + local c = decode[string.byte(text, i + 2)] + local d = decode[string.byte(text, i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d @@ -2575,7 +2563,7 @@ function ZZBase64.decode(text) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index ] = string.char(num % 256) + res[index] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2611,7 +2599,4 @@ function ZZBase64.__decodeLeft2(res, index, text, len) res[index] = string.char(num) end - - - return StartDebug diff --git a/lua_probject/base_project/LuaDebugjit.lua b/lua_probject/base_project/LuaDebugjit.lua index 6ba9f888..417172c3 100644 --- a/lua_probject/base_project/LuaDebugjit.lua +++ b/lua_probject/base_project/LuaDebugjit.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile =nil -xpcall(function() +local debugger_reLoadFile = nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end,function() +end, function() debugger_reLoadFile = function() print("未实现代码重载") end end) local sethook = debug.sethook @@ -13,165 +13,165 @@ local checkSetVar = nil local loadstring_ = nil local debugger_sendMsg = nil if (loadstring) then -loadstring_ = loadstring + loadstring_ = loadstring else -loadstring_ = load + loadstring_ = load end local ZZBase64 = {} local LuaDebugTool_ = nil if (LuaDebugTool) then - LuaDebugTool_ = LuaDebugTool + LuaDebugTool_ = LuaDebugTool elseif (CS and CS.LuaDebugTool) then - LuaDebugTool_ = CS.LuaDebugTool + LuaDebugTool_ = CS.LuaDebugTool end local LuaDebugTool = LuaDebugTool_ local loadstring = loadstring_ local getinfo = debug.getinfo local function createSocket() - local base = _G - local string = require("string") - local math = require("math") - local socket = require("socket.core") - - local _M = socket - - ----------------------------------------------------------------------------- - -- Exported auxiliar functions - ----------------------------------------------------------------------------- - function _M.connect4(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet") - end - - function _M.connect6(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet6") - end + local base = _G + local string = require("string") + local math = require("math") + local socket = require("socket.core") - if (not _M.connect) then - function _M.connect(address, port, laddress, lport) - local sock, err = socket.tcp() - if not sock then - return nil, err - end - if laddress then - local res, err = sock:bind(laddress, lport, -1) - if not res then - return nil, err - end - end - local res, err = sock:connect(address, port) - if not res then + local _M = socket + + ----------------------------------------------------------------------------- + -- Exported auxiliar functions + ----------------------------------------------------------------------------- + function _M.connect4(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet") + end + + function _M.connect6(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet6") + end + + if (not _M.connect) then + function _M.connect(address, port, laddress, lport) + local sock, err = socket.tcp() + if not sock then return nil, err end - return sock - end - end - function _M.bind(host, port, backlog) - if host == "*" then + if laddress then + local res, err = sock:bind(laddress, lport, -1) + if not res then + return nil, err + end + end + local res, err = sock:connect(address, port) + if not res then + return nil, err + end + return sock + end + end + function _M.bind(host, port, backlog) + if host == "*" then host = "0.0.0.0" end local addrinfo, err = socket.dns.getaddrinfo(host) if not addrinfo then return nil, err end - local sock, res - err = "no info on address" - for i, alt in base.ipairs(addrinfo) do - if alt.family == "inet" then - sock, err = socket.tcp4() - else - sock, err = socket.tcp6() - end - if not sock then + local sock, res + err = "no info on address" + for i, alt in base.ipairs(addrinfo) do + if alt.family == "inet" then + sock, err = socket.tcp4() + else + sock, err = socket.tcp6() + end + if not sock then return nil, err end - sock:setoption("reuseaddr", true) - res, err = sock:bind(alt.addr, port) - if not res then - sock:close() - else - res, err = sock:listen(backlog) - if not res then - sock:close() - else - return sock - end - end - end - return nil, err - end - - _M.try = _M.newtry() - - function _M.choose(table) - return function(name, opt1, opt2) - if base.type(name) ~= "string" then - name, opt1, opt2 = "default", name, opt1 - end - local f = table[name or "nil"] - if not f then + sock:setoption("reuseaddr", true) + res, err = sock:bind(alt.addr, port) + if not res then + sock:close() + else + res, err = sock:listen(backlog) + if not res then + sock:close() + else + return sock + end + end + end + return nil, err + end + + _M.try = _M.newtry() + + function _M.choose(table) + return function(name, opt1, opt2) + if base.type(name) ~= "string" then + name, opt1, opt2 = "default", name, opt1 + end + local f = table[name or "nil"] + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end - end - end - - ----------------------------------------------------------------------------- - -- Socket sources and sinks, conforming to LTN12 - ----------------------------------------------------------------------------- - -- create namespaces inside LuaSocket namespace - local sourcet, sinkt = {}, {} - _M.sourcet = sourcet - _M.sinkt = sinkt - - _M.BLOCKSIZE = 2048 - - sinkt["close-when-done"] = - function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) + end end + ----------------------------------------------------------------------------- + -- Socket sources and sinks, conforming to LTN12 + ----------------------------------------------------------------------------- + -- create namespaces inside LuaSocket namespace + local sourcet, sinkt = {}, {} + _M.sourcet = sourcet + _M.sinkt = sinkt + + _M.BLOCKSIZE = 2048 + + sinkt["close-when-done"] = + function(sock) + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) + end + end + } + ) + end + sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 + end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -179,133 +179,133 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if length <= 0 then - return nil + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err + }, + { + __call = function() + if length <= 0 then + return nil + end + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err + end + length = length - string.len(chunk) + return chunk end - length = length - string.len(chunk) - return chunk - end - } - ) - end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if done then - return nil + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err + }, + { + __call = function() + if done then + return nil + end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err + end end - end - } - ) - end - - sourcet["default"] = sourcet["until-closed"] - - _M.source = _M.choose(sourcet) - - return _M + } + ) + end + + sourcet["default"] = sourcet["until-closed"] + + _M.source = _M.choose(sourcet) + + return _M end local function createJson() - local math = require("math") - local string = require("string") - local table = require("table") - local object = nil - ----------------------------------------------------------------------------- - -- Module declaration - ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local math = require("math") + local string = require("string") + local table = require("table") + local object = nil + ----------------------------------------------------------------------------- + -- Module declaration + ----------------------------------------------------------------------------- + local json = {} -- Public namespace local json_private = {} -- Private namespace - - -- Public constants - json.EMPTY_ARRAY = {} - json.EMPTY_OBJECT = {} - -- Public functions - -- Private functions - local decode_scanArray - local decode_scanComment - local decode_scanConstant - local decode_scanNumber - local decode_scanObject - local decode_scanString - local decode_scanWhitespace - local encodeString - local isArray - local isEncodable - - ----------------------------------------------------------------------------- - -- PUBLIC FUNCTIONS - ----------------------------------------------------------------------------- - --- Encodes an arbitrary Lua object / variable. - -- @param v The Lua object / variable to be JSON encoded. - -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) - function json.encode(v) - -- Handle nil values - if v == nil then - return "null" - end - - local vtype = type(v) - - -- Handle strings - if vtype == "string" then + -- Public constants + json.EMPTY_ARRAY = {} + json.EMPTY_OBJECT = {} + -- Public functions + + -- Private functions + local decode_scanArray + local decode_scanComment + local decode_scanConstant + local decode_scanNumber + local decode_scanObject + local decode_scanString + local decode_scanWhitespace + local encodeString + local isArray + local isEncodable + + ----------------------------------------------------------------------------- + -- PUBLIC FUNCTIONS + ----------------------------------------------------------------------------- + --- Encodes an arbitrary Lua object / variable. + -- @param v The Lua object / variable to be JSON encoded. + -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) + function json.encode(v) + -- Handle nil values + if v == nil then + return "null" + end + + local vtype = type(v) + + -- Handle strings + if vtype == "string" then return '"' .. json_private.encodeString(v) .. '"' -- Need to handle encoding in string end - - -- Handle booleans - if vtype == "number" or vtype == "boolean" then + + -- Handle booleans + if vtype == "number" or vtype == "boolean" then return tostring(v) end - - -- Handle tables - if vtype == "table" then - local rval = {} - -- Consider arrays separately - local bArray, maxCount = isArray(v) - if bArray then - for i = 1, maxCount do - table.insert(rval, json.encode(v[i])) - end - else -- An object, not an array + + -- Handle tables + if vtype == "table" then + local rval = {} + -- Consider arrays separately + local bArray, maxCount = isArray(v) + if bArray then + for i = 1, maxCount do + table.insert(rval, json.encode(v[i])) + end + else -- An object, not an array for i, j in pairs(v) do if isEncodable(i) and isEncodable(j) then table.insert(rval, '"' .. json_private.encodeString(i) .. '":' .. json.encode(j)) @@ -317,23 +317,23 @@ local function createJson() else return "{" .. table.concat(rval, ",") .. "}" end - end - - -- Handle null values - if vtype == "function" and v == json.null then + end + + -- Handle null values + if vtype == "function" and v == json.null then return "null" end assert(false, "encode attempt to encode unsupported type " .. vtype .. ":" .. tostring(v)) end - - --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. - -- @param s The string to scan. - -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. - -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, - -- and the position of the first character after - -- the scanned JSON object. - function json.decode(s, startPos) + + --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. + -- @param s The string to scan. + -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. + -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, + -- and the position of the first character after + -- the scanned JSON object. + function json.decode(s, startPos) startPos = startPos and startPos or 1 startPos = decode_scanWhitespace(s, startPos) assert(startPos <= string.len(s), "Unterminated JSON encoded object found at position in [" .. s .. "]") @@ -366,18 +366,19 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - ----------------------------------------------------------------------------- - -- Internal, PRIVATE functions. - -- Following a Python-like convention, I have prefixed all these 'PRIVATE' - -- functions with an underscore. - ----------------------------------------------------------------------------- - --- Scans an array from JSON into a Lua object - -- startPos begins at the start of the array. - -- Returns the array and the next starting position - -- @param s The string being scanned. - -- @param startPos The starting position for the scan. - -- @return table, int The scanned array as a table, and the position of the next character to scan. - function decode_scanArray(s, startPos) + + ----------------------------------------------------------------------------- + -- Internal, PRIVATE functions. + -- Following a Python-like convention, I have prefixed all these 'PRIVATE' + -- functions with an underscore. + ----------------------------------------------------------------------------- + --- Scans an array from JSON into a Lua object + -- startPos begins at the start of the array. + -- Returns the array and the next starting position + -- @param s The string being scanned. + -- @param startPos The starting position for the scan. + -- @return table, int The scanned array as a table, and the position of the next character to scan. + function decode_scanArray(s, startPos) local array = {} -- The return value local stringLen = string.len(s) assert( @@ -423,8 +424,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = {["true"] = true, ["false"] = false, ["null"] = nil} - local constNames = {"true", "false", "null"} + local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } + local constNames = { "true", "false", "null" } for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -573,7 +574,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -649,13 +650,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -677,64 +678,64 @@ local debug_server = nil local breakInfoSocket = nil local json = createJson() local LuaDebugger = { - fileMaps = {}, - Run = true, --表示正常运行只检测断点 - StepIn = false, - StepNext = false, - StepOut = false, - breakInfos = {}, - runTimeType = nil, - isHook = true, - pathCachePaths = {}, - isProntToConsole = 1, - isDebugPrint = true, - hookType = "lrc", - stepNextFun = nil, - DebugLuaFie = "", - runLineCount = 0, - --分割字符串缓存 - splitFilePaths = {}, - version="0.9.3", + fileMaps = {}, + Run = true, --表示正常运行只检测断点 + StepIn = false, + StepNext = false, + StepOut = false, + breakInfos = {}, + runTimeType = nil, + isHook = true, + pathCachePaths = {}, + isProntToConsole = 1, + isDebugPrint = true, + hookType = "lrc", + stepNextFun = nil, + DebugLuaFie = "", + runLineCount = 0, + --分割字符串缓存 + splitFilePaths = {}, + version = "0.9.3", serVarLevel = 4 } local debug_hook = nil local _resume = coroutine.resume coroutine.resume = function(co, ...) - if (LuaDebugger.isHook) then + if (LuaDebugger.isHook) then if coroutine.status(co) ~= "dead" then debug.sethook(co, debug_hook, "lrc") - end + end end return _resume(co, ...) end LuaDebugger.event = { - S2C_SetBreakPoints = 1, - C2S_SetBreakPoints = 2, - S2C_RUN = 3, - C2S_HITBreakPoint = 4, - S2C_ReqVar = 5, - C2S_ReqVar = 6, - --单步跳过请求 - S2C_NextRequest = 7, - --单步跳过反馈 - C2S_NextResponse = 8, - -- 单步跳过 结束 没有下一步 - C2S_NextResponseOver = 9, - --单步跳入 - S2C_StepInRequest = 10, - C2S_StepInResponse = 11, - --单步跳出 - S2C_StepOutRequest = 12, - --单步跳出返回 - C2S_StepOutResponse = 13, - --打印 - C2S_LuaPrint = 14, - S2C_LoadLuaScript = 16, - C2S_SetSocketName = 17, - C2S_LoadLuaScript = 18, - C2S_DebugXpCall = 20, - S2C_DebugClose = 21, + S2C_SetBreakPoints = 1, + C2S_SetBreakPoints = 2, + S2C_RUN = 3, + C2S_HITBreakPoint = 4, + S2C_ReqVar = 5, + C2S_ReqVar = 6, + --单步跳过请求 + S2C_NextRequest = 7, + --单步跳过反馈 + C2S_NextResponse = 8, + -- 单步跳过 结束 没有下一步 + C2S_NextResponseOver = 9, + --单步跳入 + S2C_StepInRequest = 10, + C2S_StepInResponse = 11, + --单步跳出 + S2C_StepOutRequest = 12, + --单步跳出返回 + C2S_StepOutResponse = 13, + --打印 + C2S_LuaPrint = 14, + S2C_LoadLuaScript = 16, + C2S_SetSocketName = 17, + C2S_LoadLuaScript = 18, + C2S_DebugXpCall = 20, + S2C_DebugClose = 21, S2C_SerVar = 24, C2S_SerVar = 25, S2C_ReLoadFile = 26, @@ -742,27 +743,27 @@ LuaDebugger.event = { } --@region print function print(...) - if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then + if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 1} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 1 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end function luaIdePrintWarn(...) @@ -771,46 +772,48 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 2} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 2 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end + function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 3} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 3 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end + --@endregion --@region 辅助方法 @@ -841,23 +844,23 @@ local function debugger_convertParentDir(dir) end end -local function debugger_getFilePathInfo(file) - local fileName = nil +local function debugger_getFilePathInfo(file) + local fileName = nil local dir = nil file = file:gsub("/.\\", "/") - file = file:gsub("\\", "/") - file = file:gsub("//", "/") - + file = file:gsub("\\", "/") + file = file:gsub("//", "/") - if file:find("@") == 1 then + + if file:find("@") == 1 then file = file:sub(2) - end - local findex = file:find("%./") - if (findex == 1) then + end + local findex = file:find("%./") + if (findex == 1) then file = file:sub(3) end - file = debugger_convertParentDir(file) + file = debugger_convertParentDir(file) local fileLength = string.len(file) local suffixNames = { ".lua", @@ -886,8 +889,8 @@ local function debugger_getFilePathInfo(file) end local fileNameStartIndex = debugger_lastIndex(file, "/") if (fileNameStartIndex) then - fileName = string.sub(file, fileNameStartIndex + 1) - + fileName = string.sub(file, fileNameStartIndex + 1) + dir = string.sub(file, 1, fileNameStartIndex) file = dir .. fileName else @@ -898,12 +901,12 @@ local function debugger_getFilePathInfo(file) else dir = string.sub(file, 1, fileNameStartIndex) dir = dir:gsub("%.", "/") - fileName = string.sub(file, fileNameStartIndex + 1) - file = dir .. fileName + fileName = string.sub(file, fileNameStartIndex + 1) + file = dir .. fileName end - end + end - return file, dir, fileName + return file, dir, fileName end --@endregion @@ -915,25 +918,25 @@ end local function debugger_strSplit(input, delimiter) - input = tostring(input) - delimiter = tostring(delimiter) - if (delimiter == "") then + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter == "") then return false end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(input, delimiter, pos, true) - end do - table.insert(arr, string.sub(input, pos, st - 1)) - pos = sp + 1 - end - table.insert(arr, string.sub(input, pos)) - return arr + end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 + end + table.insert(arr, string.sub(input, pos)) + return arr end local function debugger_strTrim(input) - input = string.gsub(input, "^[ \t\n\r]+", "") - return string.gsub(input, "[ \t\n\r]+$", "") + input = string.gsub(input, "^[ \t\n\r]+", "") + return string.gsub(input, "[ \t\n\r]+$", "") end local function debugger_dump(value, desciption, nesting) if type(nesting) ~= "number" then @@ -1005,27 +1008,24 @@ local function debugger_valueToString(v) local vtype = type(v) local vstr = nil if (vtype == "userdata") then - if (LuaDebugger.isFoxGloryProject ) then - - return "userdata",vtype - + if (LuaDebugger.isFoxGloryProject) then + return "userdata", vtype else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() - if(LuaDebugger.isFoxGloryProject) then + xpcall(function() + if (LuaDebugger.isFoxGloryProject) then value = vtype else value = tostring(v) end - - end,function() + end, function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string" ) then + elseif (vtype == "number" or vtype == "string") then return v, vtype else return tostring(v), vtype @@ -1033,12 +1033,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr,nameType = debugger_valueToString(name) - if(valueStr == nil) then + local nameStr, nameType = debugger_valueToString(name) + if (valueStr == nil) then valueStr = valueType end local valueInfo = { - name =nameStr, + name = nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1047,283 +1047,282 @@ local function debugger_setVarInfo(name, value) end local function debugger_getvalue(f) - local i = 1 - local locals = {} - -- get locals - while true do - local name, value = debug.getlocal(f, i) - if not name then + local i = 1 + local locals = {} + -- get locals + while true do + local name, value = debug.getlocal(f, i) + if not name then break end if (name ~= "(*temporary)") then - locals[name] = value - end - i = i + 1 - end - local func = getinfo(f, "f").func - i = 1 - local ups = {} - while func do -- check for func as it may be nil for tail calls - local name, value = debug.getupvalue(func, i) - if not name then + locals[name] = value + end + i = i + 1 + end + local func = getinfo(f, "f").func + i = 1 + local ups = {} + while func do -- check for func as it may be nil for tail calls + local name, value = debug.getupvalue(func, i) + if not name then break end if (name == "_ENV") then - ups["_ENV_"] = value - else - ups[name] = value - end - i = i + 1 - end + ups["_ENV_"] = value + else + ups[name] = value + end + i = i + 1 + end - return {locals = locals, ups = ups} + return { locals = locals, ups = ups } end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end - end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end + end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break + end end - end - local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } + local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } - return data -end + return data + end --==============================工具方法 end====================================================== --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 --CCDirector:sharedDirector():getScheduler() local debugger_setBreak = nil local function debugger_receiveDebugBreakInfo() - if(not jit) then - if(_VERSION)then - print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") - else - print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") - end - end - if (breakInfoSocket) then + if (not jit) then + if (_VERSION) then + print("当前lua版本为: " .. _VERSION .. " 请使用 -----LuaDebug.lua----- 进行调试!") + else + print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") + end + end + if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if(LuaDebugger.isLaunch == true and status == "closed") then + if (LuaDebugger.isLaunch == true and status == "closed") then os.exit() end - if (msg) then - local netData = json.decode(msg) - if netData.event == LuaDebugger.event.S2C_SetBreakPoints then - debugger_setBreak(netData.data) - elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + if (msg) then + local netData = json.decode(msg) + if netData.event == LuaDebugger.event.S2C_SetBreakPoints then + debugger_setBreak(netData.data) + elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) LuaDebugger.reLoadFileBody.script = nil - + debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end - end - end + ) + end + end + end end local function splitFilePath(path) - if (LuaDebugger.splitFilePaths[path]) then - return LuaDebugger.splitFilePaths[path] - end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + if (LuaDebugger.splitFilePaths[path]) then + return LuaDebugger.splitFilePaths[path] + end + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(path, "/", pos, true) - end do - local pathStr = string.sub(path, pos, st - 1) - table.insert(arr, pathStr) - pos = sp + 1 - end - local pathStr = string.sub(path, pos) - table.insert(arr, pathStr) - LuaDebugger.splitFilePaths[path] = arr - return arr -end -debugger_setBreak = - function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false - end + end do + local pathStr = string.sub(path, pos, st - 1) + table.insert(arr, pathStr) + pos = sp + 1 + end + local pathStr = string.sub(path, pos) + table.insert(arr, pathStr) + LuaDebugger.splitFilePaths[path] = arr + return arr end +debugger_setBreak = + function(datas) + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] + end + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo + end + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil + end + end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end + end local function debugger_checkFileIsBreak(fileName) - return LuaDebugger.breakInfos[fileName] + return LuaDebugger.breakInfos[fileName] end --=====================================断点信息 end ---------------------------------------------- local controller_host = "192.168.1.102" local controller_port = 7003 debugger_sendMsg = function(serverSocket, eventName, data) - local sendMsg = { - event = eventName, - data = data - } - local sendStr = json.encode(sendMsg) - serverSocket:send(sendStr .. "__debugger_k0204__") + local sendMsg = { + event = eventName, + data = data + } + local sendStr = json.encode(sendMsg) + serverSocket:send(sendStr .. "__debugger_k0204__") end -function debugger_conditionStr(condition, vars, callBack) - local function loadScript() - local currentTabble = {} - - local locals = vars[1].locals - local ups = vars[1].ups - if (ups) then - for k, v in pairs(ups) do - currentTabble[k] = v - end - end - - if (locals) then - for k, v in pairs(locals) do - currentTabble[k] = v - end - end - setmetatable(currentTabble, {__index = _G}) - local fun = loadstring("return " .. condition) - setfenv(fun, currentTabble) - return fun() - end - local status, - msg = - xpcall( - loadScript, - function(error) - print(error) +function debugger_conditionStr(condition, vars, callBack) + local function loadScript() + local currentTabble = {} + + local locals = vars[1].locals + local ups = vars[1].ups + if (ups) then + for k, v in pairs(ups) do + currentTabble[k] = v + end end - ) + + if (locals) then + for k, v in pairs(locals) do + currentTabble[k] = v + end + end + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring("return " .. condition) + setfenv(fun, currentTabble) + return fun() + end + local status, + msg = + xpcall( + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end + --执行lua字符串 debugger_exeLuaString = function() - local function loadScript() - local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = {_G = _G} + local currentTabble = { _G = _G } local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1336,8 +1335,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, {__index = _G}) - + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1347,54 +1346,51 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event + .C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true - end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key,keyType,value) - if(keyType == -1) then +local function debugger_getTablekey(key, keyType, value) + if (keyType == -1) then return key - elseif(keyType == 1) then + elseif (keyType == 1) then return tonumber(key) - elseif(keyType == 2) then + elseif (keyType == 2) then local valueKey = nil - for k,v in pairs(value) do + for k, v in pairs(value) do local nameType = type(k) - if(nameType == "userdata" or nameType == "table") then + if (nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if(key == valueKey) then + if (key == valueKey) then return k end break end end end - end end local function debugger_setVarValue(server, data) - local newValue = nil - local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1409,7 +1405,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if(firstKeyName == name) then + if (firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1423,11 +1419,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if(localValueChangeIndex == -1 and firstKeyName == name) then + if (localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1439,9 +1435,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end ---@endregion - local vars = {locals = locals, ups = ups} - + --@endregion + local vars = { locals = locals, ups = ups } + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1457,58 +1453,56 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if(keyLength == 1) then - if(localValueChangeIndex ~= -1) then - + + if (keyLength == 1) then + if (localValueChangeIndex ~= -1) then debug.setlocal(level, localValueChangeIndex, newValue) - elseif(upValueFun ~= nil) then - debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) + elseif (upValueFun ~= nil) then + debug.setupvalue(upValueFun, upValueChangeIndex, newValue) else --全局变量查找 - if(_G[firstKeyName]) then + if (_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if(not oldValue) then - if(_G[firstKeyName]) then + if (not oldValue) then + if (_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i=2,keyLength-1 do - if(tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] + for i = 2, keyLength - 1 do + if (tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] end end - if(tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue + if (tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - end --@endregion @@ -1518,107 +1512,107 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server,LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - print("设置变量", error) - end - ) - elseif(LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("执行代码", error) - end - ) - elseif(LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("重新加载文件", error) - end - ) + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server, LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif (LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif (LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) + end end -end - + local function getSource(source) - source = string.lower(source) + source = string.lower(source) if (LuaDebugger.pathCachePaths[source]) then - LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] - return LuaDebugger.pathCachePaths[source] - end + LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] + return LuaDebugger.pathCachePaths[source] + end - local fullName, dir, fileName = debugger_getFilePathInfo(source) - LuaDebugger.currentLineFile = fullName - LuaDebugger.pathCachePaths[source] = fileName + local fullName, dir, fileName = debugger_getFilePathInfo(source) + LuaDebugger.currentLineFile = fullName + LuaDebugger.pathCachePaths[source] = fileName - return fileName + return fileName end local function debugger_GeVarInfoBytUserData(server, var) - local fileds = LuaDebugTool.getUserDataInfo(var) - - local varInfos = {} + local fileds = LuaDebugTool.getUserDataInfo(var) - - --c# vars - for i = 1, fileds.Count do - local filed = fileds[i - 1] - local valueInfo = { - name = filed.name, - valueType = filed.valueType, - valueStr = ZZBase64.encode(filed.valueStr), - isValue = filed.isValue, - csharp = true - } - - table.insert(varInfos, valueInfo) - end - return varInfos -end + local varInfos = {} + + + --c# vars + for i = 1, fileds.Count do + local filed = fileds[i - 1] + local valueInfo = { + name = filed.name, + valueType = filed.valueType, + valueStr = ZZBase64.encode(filed.valueStr), + isValue = filed.isValue, + csharp = true + } + + table.insert(varInfos, valueInfo) + end + return varInfos +end local function debugger_getValueByScript(value, script) - local val = nil - local status, - msg = - xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - print(error, "====>") - val = nil - end - ) + local val = nil + local status, + msg = + xpcall( + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) - return val + return val end -local function debugger_getVarByKeys(value, keys, index) - local str = "" - local keyLength = #keys - for i = index, keyLength do - local key = keys[i] - if (key == "[metatable]") then - else - if (i == index) then +local function debugger_getVarByKeys(value, keys, index) + local str = "" + local keyLength = #keys + for i = index, keyLength do + local key = keys[i] + if (key == "[metatable]") then + else + if (i == index) then if (string.find(key, "%.")) then if (str == "") then i = index + 1 @@ -1630,10 +1624,10 @@ local function debugger_getVarByKeys(value, keys, index) return debugger_getVarByKeys(value, keys, i) else - str = key - end - else - if (string.find(key, "%[")) then + str = key + end + else + if (string.find(key, "%[")) then str = str .. key elseif (type(key) == "string") then if (string.find(key, "table:") or string.find(key, "userdata:") or string.find(key, "function:")) then @@ -1712,7 +1706,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1745,7 +1739,6 @@ end return ]] local function debugger_getmetatable(value, metatable, vinfos, server, variablesReference, debugSpeedIndex, metatables) - for i, mtable in ipairs(metatables) do if (metatable == mtable) then return vinfos @@ -1794,14 +1787,13 @@ local function debugger_getmetatable(value, metatable, vinfos, server, variables end end end - + local m = getmetatable(metatable) if (m) then return debugger_getmetatable(value, m, vinfos, server, variablesReference, debugSpeedIndex, metatables) else return vinfos end - end local function debugger_sendTableField(luatable, vinfos, server, variablesReference, debugSpeedIndex, valueType) if (valueType == "userdata") then @@ -1840,12 +1832,12 @@ local function debugger_sendTableValues(value, server, variablesReference, debug local valueType = type(value) local userDataInfos = {} local m = nil - + if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1874,7 +1866,6 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end - end else m = getmetatable(value) @@ -1898,56 +1889,55 @@ end --获取lua 变量的方法 local function debugger_getBreakVar(body, server) - local variablesReference = body.variablesReference - local debugSpeedIndex = body.debugSpeedIndex - local vinfos = {} - local function exe() - local frameId = body.frameId + local variablesReference = body.variablesReference + local debugSpeedIndex = body.debugSpeedIndex + local vinfos = {} + local function exe() + local frameId = body.frameId local type_ = body.type local keys = body.keys - --找到对应的var - local vars = nil - if (type_ == 1) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.locals - elseif (type_ == 2) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.ups - elseif (type_ == 3) then - vars = _G - end - if (#keys == 0) then - debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) - return - end - local index, value = debugger_searchVarByKeys(vars, keys, keys) - if (value) then - local valueType = type(value) + --找到对应的var + local vars = nil + if (type_ == 1) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.locals + elseif (type_ == 2) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.ups + elseif (type_ == 3) then + vars = _G + end + if (#keys == 0) then + debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) + return + end + local index, value = debugger_searchVarByKeys(vars, keys, keys) + if (value) then + local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) - else + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) + else if (valueType == "function") then - if(LuaDebugger.isFoxGloryProject) then - value = "function" + if (LuaDebugger.isFoxGloryProject) then + value = "function" else value = tostring(value) end - end - debugger_sendMsg( + end + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { - variablesReference = variablesReference, - debugSpeedIndex = debugSpeedIndex, - vars = ZZBase64.encode(value), - isComplete = 1, - varType = valueType - } + variablesReference = variablesReference, + debugSpeedIndex = debugSpeedIndex, + vars = ZZBase64.encode(value), + isComplete = 1, + varType = valueType + } ) - end - else - debugger_sendMsg( + end + else + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { @@ -1958,9 +1948,9 @@ local function debugger_getBreakVar(body, server) varType = "nil" } ) - end - end - xpcall( + end + end + xpcall( exe, function(error) -- print("获取变量错误 错误消息-----------------") @@ -1987,64 +1977,62 @@ local function debugger_getBreakVar(body, server) ) end local function ResetDebugInfo() - LuaDebugger.Run = false - LuaDebugger.StepIn = false - LuaDebugger.StepNext = false - LuaDebugger.StepOut = false - + LuaDebugger.Run = false + LuaDebugger.StepIn = false + LuaDebugger.StepNext = false + LuaDebugger.StepOut = false end local function debugger_loop(server) - server = debug_server - --命令 - local command - local eval_env = {} - local arg - while true do - local line, status = server:receive() - if (status == "closed") then - if(LuaDebugger.isLaunch) then + server = debug_server + --命令 + local command + local eval_env = {} + local arg + while true do + local line, status = server:receive() + if (status == "closed") then + if (LuaDebugger.isLaunch) then os.exit() else debug.sethook() coroutine.yield() end - end - if (line) then - local netData = json.decode(line) - local event = netData.event + end + if (line) then + local netData = json.decode(line) + local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - - elseif event == LuaDebugger.event.S2C_SetBreakPoints then - --设置断点信息 - local function setB() - debugger_setBreak(body) - end - xpcall( + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + elseif event == LuaDebugger.event.S2C_SetBreakPoints then + --设置断点信息 + local function setB() + debugger_setBreak(body) + end + xpcall( setB, function(error) print(error) end ) - elseif event == LuaDebugger.event.S2C_RUN then --开始运行 - LuaDebugger.runTimeType = body.runTimeType - LuaDebugger.isProntToConsole = body.isProntToConsole + elseif event == LuaDebugger.event.S2C_RUN then --开始运行 + LuaDebugger.runTimeType = body.runTimeType + LuaDebugger.isProntToConsole = body.isProntToConsole LuaDebugger.isFoxGloryProject = body.isFoxGloryProject LuaDebugger.isLaunch = body.isLaunch - ResetDebugInfo() - LuaDebugger.currentDebuggerData = nil - LuaDebugger.Run = true + ResetDebugInfo() + LuaDebugger.currentDebuggerData = nil + LuaDebugger.Run = true LuaDebugger.tempRunFlag = true - LuaDebugger.currentLine= nil - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - LuaDebugger.currentDebuggerData = data + LuaDebugger.currentLine = nil + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + LuaDebugger.currentDebuggerData = data debugger_sendMsg( server, data.event, @@ -2052,58 +2040,58 @@ local function debugger_loop(server) stack = data.stack } ) - elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 - --请求数据信息 - debugger_getBreakVar(body, server) - elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 - ResetDebugInfo() - LuaDebugger.StepNext = true - --设置当前文件名和当前行数 - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 + --请求数据信息 + debugger_getBreakVar(body, server) + elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 + ResetDebugInfo() + LuaDebugger.StepNext = true + --设置当前文件名和当前行数 + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { stack = data.stack } ) - elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 - --单步跳入 - ResetDebugInfo() - LuaDebugger.StepIn = true - - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 + --单步跳入 + ResetDebugInfo() + LuaDebugger.StepIn = true + + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif (event == LuaDebugger.event.S2C_StepOutRequest) then - --单步跳出 - ResetDebugInfo() - LuaDebugger.StepOut = true - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + stack = data.stack, + eventType = data.eventType + } + ) + elseif (event == LuaDebugger.event.S2C_StepOutRequest) then + --单步跳出 + ResetDebugInfo() + LuaDebugger.StepOut = true + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif event == LuaDebugger.event.S2C_LoadLuaScript then + stack = data.stack, + eventType = data.eventType + } + ) + elseif event == LuaDebugger.event.S2C_LoadLuaScript then LuaDebugger.loadScriptBody = body LuaDebugger.isLoadLuaScript = true local data = coroutine.yield() @@ -2123,8 +2111,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2135,340 +2123,321 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - end - end - end + ) + end + end + end end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) + if (not LuaDebugger.isHook) then + return + end - if(not LuaDebugger.isHook) then - return - end + if (LuaDebugger.Run) then + if (event == "line") then + local isCheck = false + for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do + if (linesInfo.lines and linesInfo.lines[line]) then + isCheck = true + break + end + end + if (isCheck) then + break + end + end - if(LuaDebugger.Run) then - if(event == "line") then - local isCheck = false - for k, breakInfo in pairs(LuaDebugger.breakInfos) do + if (not isCheck) then + return + end + end + end - for bk, linesInfo in pairs(breakInfo) do - - if(linesInfo.lines and linesInfo.lines[line]) then - isCheck = true - break - end - end - if(isCheck) then - break - end - end - - if(not isCheck) then - return - end - - end - end - - - local file = nil - if(event == "line") then - - local funs = nil - local funlength =0 - if(LuaDebugger.currentDebuggerData) then - funs = LuaDebugger.currentDebuggerData.funcs - funlength = #funs - end - local stepInfo = getinfo(2) - local tempFunc = stepInfo.func - local source = stepInfo.source - file = getSource(source); - if(source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end - if(funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then - LuaDebugger.runLineCount = LuaDebugger.runLineCount+1 - end - local breakInfo = LuaDebugger.breakInfos[file] - local breakData = nil - local ischeck = false - if(breakInfo) then - - for k, lineInfo in pairs(breakInfo) do - local lines = lineInfo.lines - if(lines and lines[line]) then - ischeck = true - break - end - end - end - local isHit = false - if(ischeck) then - - --并且在断点中 - local info = stepInfo - local source = string.lower( info.source ) - local fullName,dir,fileName = debugger_getFilePathInfo(source) - local hitPathNames = splitFilePath(fullName) - - local hitCounts = {} - local debugHitCounts = nil - for k, lineInfo in pairs(breakInfo) do + local file = nil + if (event == "line") then + local funs = nil + local funlength = 0 + if (LuaDebugger.currentDebuggerData) then + funs = LuaDebugger.currentDebuggerData.funcs + funlength = #funs + end + local stepInfo = getinfo(2) + local tempFunc = stepInfo.func + local source = stepInfo.source + file = getSource(source); + if (source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end + if (funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then + LuaDebugger.runLineCount = LuaDebugger.runLineCount + 1 + end + local breakInfo = LuaDebugger.breakInfos[file] + local breakData = nil + local ischeck = false + if (breakInfo) then + for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines - local pathNames = lineInfo.pathNames - debugHitCounts = lineInfo.hitCounts - if(lines and lines[line]) then - breakData = lines[line] - --判断路径 - hitCounts[k] = 0 - local hitPathNamesCount = #hitPathNames - local pathNamesCount = #pathNames - local checkCount = 0; - while(true) do - if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then - break - else - hitCounts[k] = hitCounts[k] + 1 - end - pathNamesCount = pathNamesCount - 1 - hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount+1 - if(pathNamesCount <= 0 or hitPathNamesCount <= 0) then - break - end - end - if(checkCount>0) then - break; - end - else - breakData = nil - end - end - if(breakData) then - local hitFieName = "" - local maxCount = 0 - for k, v in pairs(hitCounts) do - if(v > maxCount) then - maxCount = v - hitFieName = k; - end - end - local hitPathNamesLength = #hitPathNames - if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then - if(hitFieName ~= "") then + if (lines and lines[line]) then + ischeck = true + break + end + end + end + local isHit = false + if (ischeck) then + --并且在断点中 + local info = stepInfo + local source = string.lower(info.source) + local fullName, dir, fileName = debugger_getFilePathInfo(source) + local hitPathNames = splitFilePath(fullName) + local hitCounts = {} + local debugHitCounts = nil + for k, lineInfo in pairs(breakInfo) do + local lines = lineInfo.lines + local pathNames = lineInfo.pathNames + debugHitCounts = lineInfo.hitCounts + if (lines and lines[line]) then + breakData = lines[line] + --判断路径 + hitCounts[k] = 0 + local hitPathNamesCount = #hitPathNames + local pathNamesCount = #pathNames + local checkCount = 0; + while (true) do + if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then + break + else + hitCounts[k] = hitCounts[k] + 1 + end + pathNamesCount = pathNamesCount - 1 + hitPathNamesCount = hitPathNamesCount - 1 + checkCount = checkCount + 1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then + break + end + end + if (checkCount > 0) then + break; + end + else + breakData = nil + end + end + if (breakData) then + local hitFieName = "" + local maxCount = 0 + for k, v in pairs(hitCounts) do + if (v > maxCount) then + maxCount = v + hitFieName = k; + end + end + local hitPathNamesLength = #hitPathNames + if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then + if (hitFieName ~= "") then local hitCount = breakData.hitCondition - local clientHitCount = debugHitCounts[breakData.line] - clientHitCount = clientHitCount + 1 - debugHitCounts[breakData.line] = clientHitCount - if(funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - LuaDebugger.runLineCount = 0 - elseif(LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then - LuaDebugger.runLineCount = 0 - LuaDebugger.tempRunFlag = nil - elseif(clientHitCount >= hitCount) then - isHit = true - end - - end - end - end - end - if(LuaDebugger.StepOut) then - if(funlength == 1) then - ResetDebugInfo(); - LuaDebugger.Run = true - return - else - if(funs[2] == tempFunc) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- print("StepIn 挂起") - --挂起等待调试器作出反应 + local clientHitCount = debugHitCounts[breakData.line] + clientHitCount = clientHitCount + 1 + debugHitCounts[breakData.line] = clientHitCount + if (funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + LuaDebugger.runLineCount = 0 + elseif (LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then + LuaDebugger.runLineCount = 0 + LuaDebugger.tempRunFlag = nil + elseif (clientHitCount >= hitCount) then + isHit = true + end + end + end + end + end + if (LuaDebugger.StepOut) then + if (funlength == 1) then + ResetDebugInfo(); + LuaDebugger.Run = true + return + else + if (funs[2] == tempFunc) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - end - - if(LuaDebugger.StepIn) then - if(funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - return - end - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- print("StepIn 挂起") - --挂起等待调试器作出反应 + return + end + end + end + + if (LuaDebugger.StepIn) then + if (funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + return + end + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - - if(LuaDebugger.StepNext ) then - local isNext = false - if(funs) then - for i,f in ipairs(funs) do - if(tempFunc == f) then - if(LuaDebugger.currentLine == line) then - return - end - isNext =true - break; - end - end + return + end + + if (LuaDebugger.StepNext) then + local isNext = false + if (funs) then + for i, f in ipairs(funs) do + if (tempFunc == f) then + if (LuaDebugger.currentLine == line) then + return + end + isNext = true + break; + end + end else - - isNext =true - end - if(isNext) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - --挂起等待调试器作出反应 + isNext = true + end + if (isNext) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - - local sevent = nil - + return + end + end - --断点判断 - if(isHit) then - + local sevent = nil - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - sevent = LuaDebugger.event.C2S_HITBreakPoint - --调用 coro_debugger 并传入 参数 - local data = debugger_stackInfo(3, sevent) - --挂起等待调试器作出反应 - if(breakData and breakData.condition) then - debugger_conditionStr(breakData.condition,data.vars,function() + + --断点判断 + if (isHit) then + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + sevent = LuaDebugger.event.C2S_HITBreakPoint + --调用 coro_debugger 并传入 参数 + local data = debugger_stackInfo(3, sevent) + --挂起等待调试器作出反应 + if (breakData and breakData.condition) then + debugger_conditionStr(breakData.condition, data.vars, function() _resume(coro_debugger, data) checkSetVar() - end) - else - --挂起等待调试器作出反应 + end) + else + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - end - end - end + end + end + end end local function debugger_xpcall() - --调用 coro_debugger 并传入 参数 + --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if(data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if (data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end - --挂起等待调试器作出反应 + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() end --调试开始 local function start() - - local socket = createSocket() - print(controller_host) - print(controller_port) - - local fullName,dirName,fileName = debugger_getFilePathInfo(getinfo(1).source) - LuaDebugger.DebugLuaFie = fileName - local server = socket.connect(controller_host, controller_port) - debug_server = server; - if server then - --创建breakInfo socket - socket = createSocket() - breakInfoSocket = socket.connect(controller_host, controller_port) - if(breakInfoSocket) then - breakInfoSocket:settimeout(0) - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { - name = "breakPointSocket" - }) - - - debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { - name = "mainSocket", - version = LuaDebugger.version + local socket = createSocket() + print(controller_host) + print(controller_port) - }) - xpcall(function() - sethook(debug_hook, "lrc") - end, function(error) - print("error:", error) - end) - if(not jit) then - if(_VERSION)then - print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") - else - print("当前为lua版本,请使用LuaDebug 进行调试!") - end - - end - _resume(coro_debugger, server) - end - end + local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) + LuaDebugger.DebugLuaFie = fileName + local server = socket.connect(controller_host, controller_port) + debug_server = server; + if server then + --创建breakInfo socket + socket = createSocket() + breakInfoSocket = socket.connect(controller_host, controller_port) + if (breakInfoSocket) then + breakInfoSocket:settimeout(0) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { + name = "breakPointSocket" + }) + + + debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { + name = "mainSocket", + version = LuaDebugger.version + + }) + xpcall(function() + sethook(debug_hook, "lrc") + end, function(error) + print("error:", error) + end) + if (not jit) then + if (_VERSION) then + print("当前lua版本为: " .. _VERSION .. " 请使用LuaDebug 进行调试!") + else + print("当前为lua版本,请使用LuaDebug 进行调试!") + end + end + _resume(coro_debugger, server) + end + end end function StartDebug(host, port) - - - if(not host) then - print("error host nil") - end - if(not port) then - print("error prot nil") - end - if(type(host) ~= "string") then - print("error host not string") - end - if(type(port) ~= "number") then - print("error host not number") - end - controller_host = host - controller_port = port - xpcall(start, function(error) - -- body - print(error) - end) - return debugger_receiveDebugBreakInfo, debugger_xpcall + if (not host) then + print("error host nil") + end + if (not port) then + print("error prot nil") + end + if (type(host) ~= "string") then + print("error host not string") + end + if (type(port) ~= "number") then + print("error host not number") + end + controller_host = host + controller_port = port + xpcall(start, function(error) + -- body + print(error) + end) + return debugger_receiveDebugBreakInfo, debugger_xpcall end - - --base64 local string = string ZZBase64.__code = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', - }; + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', +}; ZZBase64.__decode = {} -for k,v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v,1)] = k - 1 +for k, v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v, 1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i ) + local a = string.byte(text, i) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c - local num = a * 65536 + b * 256 + c + local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4-j) * 6))) + local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2479,52 +2448,52 @@ function ZZBase64.encode(text) if left == 1 then ZZBase64.__left1(res, index, text, len) elseif left == 2 then - ZZBase64.__left2(res, index, text, len) + ZZBase64.__left2(res, index, text, len) end return table.concat(res) end function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) - num1 = num1 * 1024 --lshift 10 + num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 - + local tmp1 = math.floor(num / 4096) --rShift 12 local curPos = tmp1 % 64 + 1 res[index] = ZZBase64.__code[curPos] - + local tmp2 = math.floor(num / 64) curPos = tmp2 % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 2] = ZZBase64.__code[curPos] - - res[index + 3] = "=" + + res[index + 3] = "=" end -function ZZBase64.__left1(res, index,text, len) +function ZZBase64.__left1(res, index, text, len) local num = string.byte(text, len + 1) - num = num * 16 - + num = num * 16 + local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index ] = ZZBase64.__code[curPos] - + res[index] = ZZBase64.__code[curPos] + curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] - - res[index + 2] = "=" - res[index + 3] = "=" + + res[index + 2] = "=" + res[index + 3] = "=" end function ZZBase64.decode(text) local len = string.len(text) - local left = 0 + local left = 0 if string.sub(text, len - 1) == "==" then - left = 2 + left = 2 len = len - 4 elseif string.sub(text, len) == "=" then left = 1 @@ -2534,20 +2503,20 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i =1, len, 4 do - local a = decode[string.byte(text,i )] - local b = decode[string.byte(text,i + 1)] - local c = decode[string.byte(text,i + 2)] - local d = decode[string.byte(text,i + 3)] + for i = 1, len, 4 do + local a = decode[string.byte(text, i)] + local b = decode[string.byte(text, i + 1)] + local c = decode[string.byte(text, i + 2)] + local d = decode[string.byte(text, i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d - + local e = string.char(num % 256) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index ] = string.char(num % 256) + res[index] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2563,11 +2532,11 @@ end function ZZBase64.__decodeLeft1(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] - local b = decode[string.byte(text, len + 2)] - local c = decode[string.byte(text, len + 3)] + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local c = decode[string.byte(text, len + 3)] local num = a * 4096 + b * 64 + c - + local num1 = math.floor(num / 1024) % 256 local num2 = math.floor(num / 4) % 256 res[index] = string.char(num1) @@ -2576,14 +2545,11 @@ end function ZZBase64.__decodeLeft2(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] + local a = decode[string.byte(text, len + 1)] local b = decode[string.byte(text, len + 2)] local num = a * 64 + b num = math.floor(num / 16) res[index] = string.char(num) end - - - return StartDebug diff --git a/lua_probject/base_project/debug/LuaDebug.lua b/lua_probject/base_project/debug/LuaDebug.lua index f7481d24..26abf930 100644 --- a/lua_probject/base_project/debug/LuaDebug.lua +++ b/lua_probject/base_project/debug/LuaDebug.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile =nil -xpcall(function() +local debugger_reLoadFile = nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end,function() +end, function() debugger_reLoadFile = function() print("未实现代码重载") end end) local debugger_stackInfo = nil @@ -21,27 +21,27 @@ local setfenv = setfenv if (not setfenv) then setfenv = function(fn, env) - local i = 1 - while true do - local name = debug.getupvalue(fn, i) - if name == "_ENV" then - debug.upvaluejoin( - fn, - i, - (function() - return env - end), - 1 - ) - break - elseif not name then - break - end + local i = 1 + while true do + local name = debug.getupvalue(fn, i) + if name == "_ENV" then + debug.upvaluejoin( + fn, + i, + (function() + return env + end), + 1 + ) + break + elseif not name then + break + end - i = i + 1 + i = i + 1 + end + return fn end - return fn - end end local ZZBase64 = {} local LuaDebugTool_ = nil @@ -154,50 +154,50 @@ local function createSocket() sinkt["close-when-done"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) + end + end + } + ) + end sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 + end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -205,63 +205,63 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if length <= 0 then - return nil + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err + }, + { + __call = function() + if length <= 0 then + return nil + end + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err + end + length = length - string.len(chunk) + return chunk end - length = length - string.len(chunk) - return chunk - end - } - ) - end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if done then - return nil + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err + }, + { + __call = function() + if done then + return nil + end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err + end end - end - } - ) - end + } + ) + end sourcet["default"] = sourcet["until-closed"] @@ -278,7 +278,7 @@ local function createJson() ----------------------------------------------------------------------------- -- Module declaration ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local json = {} -- Public namespace local json_private = {} -- Private namespace -- Public constants @@ -392,6 +392,7 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end + ----------------------------------------------------------------------------- -- Internal, PRIVATE functions. -- Following a Python-like convention, I have prefixed all these 'PRIVATE' @@ -449,8 +450,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = {["true"] = true, ["false"] = false, ["null"] = nil} - local constNames = {"true", "false", "null"} + local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } + local constNames = { "true", "false", "null" } for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -599,7 +600,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -675,13 +676,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -704,7 +705,7 @@ local breakInfoSocket = nil local json = createJson() local LuaDebugger = { fileMaps = {}, - Run = true, --表示正常运行只检测断点 + Run = true, --表示正常运行只检测断点 StepIn = false, StepInLevel = 0, StepNext = false, @@ -776,17 +777,17 @@ function print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 1} + data = { msg = ZZBase64.encode(str), type = 1 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") @@ -800,46 +801,48 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 2} + data = { msg = ZZBase64.encode(str), type = 2 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end + function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} + arg = { "nil" } end for k, v in pairs(arg) do str = str .. tostring(v) .. "\t" end local sendMsg = { event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 3} + data = { msg = ZZBase64.encode(str), type = 3 } } local sendStr = json.encode(sendMsg) debug_server:send(sendStr .. "__debugger_k0204__") end end end + --@endregion --@region 辅助方法 @@ -876,7 +879,7 @@ local function debugger_getFilePathInfo(file) file = file:gsub("/.\\", "/") file = file:gsub("\\", "/") file = file:gsub("//", "/") - + if file:find("@") == 1 then file = file:sub(2) @@ -1031,25 +1034,23 @@ local function debugger_dump(value, desciption, nesting) end --@endregion local function debugger_valueToString(v) - local vtype = type(v) + local vtype = type(v) local vstr = nil if (vtype == "userdata") then if (LuaDebugger.isFoxGloryProject) then - - return "userdata",vtype - + return "userdata", vtype else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() + xpcall(function() value = tostring(v) - end,function() + end, function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string" ) then + elseif (vtype == "number" or vtype == "string") then return v, vtype else return tostring(v), vtype @@ -1057,12 +1058,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr,nameType = debugger_valueToString(name) - if(valueStr == nil) then + local nameStr, nameType = debugger_valueToString(name) + if (valueStr == nil) then valueStr = valueType end local valueInfo = { - name =nameStr, + name = nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1100,64 +1101,64 @@ local function debugger_getvalue(f) i = i + 1 end - return {locals = locals, ups = ups} + return { locals = locals, ups = ups } end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end end - if (file == "=[C]") then - isadd = false + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break end end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break - end - end - - local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } - LuaDebugger.currentTempFunc = data.funcs[1] - return data -end + + local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } + LuaDebugger.currentTempFunc = data.funcs[1] + return data + end --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 @@ -1172,32 +1173,32 @@ local function debugger_receiveDebugBreakInfo() end if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if(LuaDebugger.isLaunch and status == "closed") then - os.exit() + if (LuaDebugger.isLaunch and status == "closed") then + os.exit() end if (msg) then local netData = json.decode(msg) if netData.event == LuaDebugger.event.S2C_SetBreakPoints then debugger_setBreak(netData.data) elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) LuaDebugger.reLoadFileBody.script = nil debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end + ) + end end end end @@ -1221,76 +1222,76 @@ local function splitFilePath(path) end debugger_setBreak = function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end end end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil end end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false end -end local function debugger_checkFileIsBreak(fileName) return LuaDebugger.breakInfos[fileName] end @@ -1322,31 +1323,30 @@ function debugger_conditionStr(condition, vars, callBack) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. condition) setfenv(fun, currentTabble) return fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error) - end - ) + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end + --执行lua字符串 debugger_exeLuaString = function() - local function loadScript() - local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = {_G = _G} + local currentTabble = { _G = _G } local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1359,8 +1359,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, {__index = _G}) - + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1370,54 +1370,51 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event + .C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true - end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key,keyType,value) - if(keyType == -1) then +local function debugger_getTablekey(key, keyType, value) + if (keyType == -1) then return key - elseif(keyType == 1) then + elseif (keyType == 1) then return tonumber(key) - elseif(keyType == 2) then + elseif (keyType == 2) then local valueKey = nil - for k,v in pairs(value) do + for k, v in pairs(value) do local nameType = type(k) - if(nameType == "userdata" or nameType == "table") then + if (nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if(key == valueKey) then + if (key == valueKey) then return k end break end end end - end end local function debugger_setVarValue(server, data) - local newValue = nil - local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1432,7 +1429,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if(firstKeyName == name) then + if (firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1446,11 +1443,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if(localValueChangeIndex == -1 and firstKeyName == name) then + if (localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1462,9 +1459,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end ---@endregion - local vars = {locals = locals, ups = ups} - + --@endregion + local vars = { locals = locals, ups = ups } + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1480,58 +1477,56 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if(keyLength == 1) then - if(localValueChangeIndex ~= -1) then - + + if (keyLength == 1) then + if (localValueChangeIndex ~= -1) then debug.setlocal(level, localValueChangeIndex, newValue) - elseif(upValueFun ~= nil) then - debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) + elseif (upValueFun ~= nil) then + debug.setupvalue(upValueFun, upValueChangeIndex, newValue) else --全局变量查找 - if(_G[firstKeyName]) then + if (_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if(not oldValue) then - if(_G[firstKeyName]) then + if (not oldValue) then + if (_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i=2,keyLength-1 do - if(tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] + for i = 2, keyLength - 1 do + if (tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] end end - if(tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue + if (tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - end --@endregion @@ -1541,44 +1536,44 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server,LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - print("设置变量", error) - end - ) - elseif(LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("执行代码", error) - end - ) - elseif(LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("重新加载文件", error) - end - ) + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server, LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif (LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif (LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) + end end -end - + local function getSource(source) @@ -1598,7 +1593,7 @@ local function debugger_GeVarInfoBytUserData(server, var) local fileds = LuaDebugTool.getUserDataInfo(var) local varInfos = {} - + --c# vars for i = 1, fileds.Count do @@ -1619,18 +1614,18 @@ end local function debugger_getValueByScript(value, script) local val = nil local status, - msg = + msg = xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - print(error, "====>") - val = nil - end - ) + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) return val end @@ -1735,7 +1730,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1863,9 +1858,9 @@ local function debugger_sendTableValues(value, server, variablesReference, debug if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1894,7 +1889,6 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end - end else m = getmetatable(value) @@ -1944,7 +1938,6 @@ local function debugger_getBreakVar(body, server) if (value) then local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) else if (valueType == "function") then @@ -2018,25 +2011,24 @@ local function debugger_loop(server) while true do local line, status = server:receive() if (status == "closed") then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end end if (line) then local netData = json.decode(line) local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end elseif event == LuaDebugger.event.S2C_SetBreakPoints then --设置断点信息 local function setB() @@ -2137,8 +2129,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2156,29 +2148,26 @@ local function debugger_loop(server) end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) - - if(not LuaDebugger.isHook) then + if (not LuaDebugger.isHook) then return end - - if(LuaDebugger.Run) then - if(event == "line") then + + if (LuaDebugger.Run) then + if (event == "line") then local isCheck = false for k, breakInfo in pairs(LuaDebugger.breakInfos) do - for bk, linesInfo in pairs(breakInfo) do - - if(linesInfo.lines and linesInfo.lines[line]) then + if (linesInfo.lines and linesInfo.lines[line]) then isCheck = true break end end - if(isCheck) then - break - end + if (isCheck) then + break + end end - if(not isCheck) then + if (not isCheck) then return end else @@ -2200,8 +2189,8 @@ debug_hook = function(event, line) else if (LuaDebugger.currentDebuggerData.funcs[2] == tempFun) then local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - --挂起等待调试器作出反应 - + --挂起等待调试器作出反应 + _resume(coro_debugger, data) checkSetVar() end @@ -2254,12 +2243,11 @@ debug_hook = function(event, line) LuaDebugger.currentFileName = file end file = LuaDebugger.currentFileName - + --判断断点 local breakInfo = LuaDebugger.breakInfos[file] local breakData = nil if (breakInfo) then - local ischeck = false for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines @@ -2268,7 +2256,7 @@ debug_hook = function(event, line) break end end - + if (ischeck) then --并且在断点中 local info = stepInfo @@ -2276,7 +2264,7 @@ debug_hook = function(event, line) info = getinfo(2) end local hitPathNames = splitFilePath(LuaDebugger.currentLineFile) - + local hitCounts = {} local debugHitCounts = nil for k, lineInfo in pairs(breakInfo) do @@ -2288,7 +2276,7 @@ debug_hook = function(event, line) --判断路径 hitCounts[k] = 0 local hitPathNamesCount = #hitPathNames - + local pathNamesCount = #pathNames local checkCount = 0; while (true) do @@ -2299,13 +2287,13 @@ debug_hook = function(event, line) end pathNamesCount = pathNamesCount - 1 hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount+1 - + checkCount = checkCount + 1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then break end end - if(checkCount>0) then + if (checkCount > 0) then break; end else @@ -2354,8 +2342,8 @@ debug_hook = function(event, line) local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) -- 挂起等待调试器作出反应 if (data) then - LuaDebugger.currentTempFunc = data.funcs[1] - + LuaDebugger.currentTempFunc = data.funcs[1] + _resume(coro_debugger, data) checkSetVar() return @@ -2384,8 +2372,8 @@ end local function debugger_xpcall() --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if(data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if (data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end --挂起等待调试器作出反应 _resume(coro_debugger, data) @@ -2438,7 +2426,7 @@ local function start() print(msg) end end - _resume(coro_debugger, server) + _resume(coro_debugger, server) end end end @@ -2478,25 +2466,25 @@ ZZBase64.__code = { 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', }; ZZBase64.__decode = {} -for k,v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v,1)] = k - 1 +for k, v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v, 1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i ) + local a = string.byte(text, i) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4-j) * 6))) + local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2516,7 +2504,7 @@ function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 local tmp1 = math.floor(num / 4096) --rShift 12 @@ -2533,13 +2521,13 @@ function ZZBase64.__left2(res, index, text, len) res[index + 3] = "=" end -function ZZBase64.__left1(res, index,text, len) +function ZZBase64.__left1(res, index, text, len) local num = string.byte(text, len + 1) num = num * 16 local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index ] = ZZBase64.__code[curPos] + res[index] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] @@ -2562,11 +2550,11 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i =1, len, 4 do - local a = decode[string.byte(text,i )] - local b = decode[string.byte(text,i + 1)] - local c = decode[string.byte(text,i + 2)] - local d = decode[string.byte(text,i + 3)] + for i = 1, len, 4 do + local a = decode[string.byte(text, i)] + local b = decode[string.byte(text, i + 1)] + local c = decode[string.byte(text, i + 2)] + local d = decode[string.byte(text, i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d @@ -2575,7 +2563,7 @@ function ZZBase64.decode(text) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index ] = string.char(num % 256) + res[index] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2611,7 +2599,4 @@ function ZZBase64.__decodeLeft2(res, index, text, len) res[index] = string.char(num) end - - - return StartDebug diff --git a/lua_probject/base_project/debug/LuaDebugjit.lua b/lua_probject/base_project/debug/LuaDebugjit.lua index 6ba9f888..417172c3 100644 --- a/lua_probject/base_project/debug/LuaDebugjit.lua +++ b/lua_probject/base_project/debug/LuaDebugjit.lua @@ -1,7 +1,7 @@ -local debugger_reLoadFile =nil -xpcall(function() +local debugger_reLoadFile = nil +xpcall(function() debugger_reLoadFile = require("luaideReLoadFile") -end,function() +end, function() debugger_reLoadFile = function() print("未实现代码重载") end end) local sethook = debug.sethook @@ -13,165 +13,165 @@ local checkSetVar = nil local loadstring_ = nil local debugger_sendMsg = nil if (loadstring) then -loadstring_ = loadstring + loadstring_ = loadstring else -loadstring_ = load + loadstring_ = load end local ZZBase64 = {} local LuaDebugTool_ = nil if (LuaDebugTool) then - LuaDebugTool_ = LuaDebugTool + LuaDebugTool_ = LuaDebugTool elseif (CS and CS.LuaDebugTool) then - LuaDebugTool_ = CS.LuaDebugTool + LuaDebugTool_ = CS.LuaDebugTool end local LuaDebugTool = LuaDebugTool_ local loadstring = loadstring_ local getinfo = debug.getinfo local function createSocket() - local base = _G - local string = require("string") - local math = require("math") - local socket = require("socket.core") - - local _M = socket - - ----------------------------------------------------------------------------- - -- Exported auxiliar functions - ----------------------------------------------------------------------------- - function _M.connect4(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet") - end - - function _M.connect6(address, port, laddress, lport) - return socket.connect(address, port, laddress, lport, "inet6") - end + local base = _G + local string = require("string") + local math = require("math") + local socket = require("socket.core") - if (not _M.connect) then - function _M.connect(address, port, laddress, lport) - local sock, err = socket.tcp() - if not sock then - return nil, err - end - if laddress then - local res, err = sock:bind(laddress, lport, -1) - if not res then - return nil, err - end - end - local res, err = sock:connect(address, port) - if not res then + local _M = socket + + ----------------------------------------------------------------------------- + -- Exported auxiliar functions + ----------------------------------------------------------------------------- + function _M.connect4(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet") + end + + function _M.connect6(address, port, laddress, lport) + return socket.connect(address, port, laddress, lport, "inet6") + end + + if (not _M.connect) then + function _M.connect(address, port, laddress, lport) + local sock, err = socket.tcp() + if not sock then return nil, err end - return sock - end - end - function _M.bind(host, port, backlog) - if host == "*" then + if laddress then + local res, err = sock:bind(laddress, lport, -1) + if not res then + return nil, err + end + end + local res, err = sock:connect(address, port) + if not res then + return nil, err + end + return sock + end + end + function _M.bind(host, port, backlog) + if host == "*" then host = "0.0.0.0" end local addrinfo, err = socket.dns.getaddrinfo(host) if not addrinfo then return nil, err end - local sock, res - err = "no info on address" - for i, alt in base.ipairs(addrinfo) do - if alt.family == "inet" then - sock, err = socket.tcp4() - else - sock, err = socket.tcp6() - end - if not sock then + local sock, res + err = "no info on address" + for i, alt in base.ipairs(addrinfo) do + if alt.family == "inet" then + sock, err = socket.tcp4() + else + sock, err = socket.tcp6() + end + if not sock then return nil, err end - sock:setoption("reuseaddr", true) - res, err = sock:bind(alt.addr, port) - if not res then - sock:close() - else - res, err = sock:listen(backlog) - if not res then - sock:close() - else - return sock - end - end - end - return nil, err - end - - _M.try = _M.newtry() - - function _M.choose(table) - return function(name, opt1, opt2) - if base.type(name) ~= "string" then - name, opt1, opt2 = "default", name, opt1 - end - local f = table[name or "nil"] - if not f then + sock:setoption("reuseaddr", true) + res, err = sock:bind(alt.addr, port) + if not res then + sock:close() + else + res, err = sock:listen(backlog) + if not res then + sock:close() + else + return sock + end + end + end + return nil, err + end + + _M.try = _M.newtry() + + function _M.choose(table) + return function(name, opt1, opt2) + if base.type(name) ~= "string" then + name, opt1, opt2 = "default", name, opt1 + end + local f = table[name or "nil"] + if not f then base.error("unknown key (" .. base.tostring(name) .. ")", 3) else return f(opt1, opt2) end - end - end - - ----------------------------------------------------------------------------- - -- Socket sources and sinks, conforming to LTN12 - ----------------------------------------------------------------------------- - -- create namespaces inside LuaSocket namespace - local sourcet, sinkt = {}, {} - _M.sourcet = sourcet - _M.sinkt = sinkt - - _M.BLOCKSIZE = 2048 - - sinkt["close-when-done"] = - function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if not chunk then - sock:close() - return 1 - else - return sock:send(chunk) - end - end - } - ) + end end + ----------------------------------------------------------------------------- + -- Socket sources and sinks, conforming to LTN12 + ----------------------------------------------------------------------------- + -- create namespaces inside LuaSocket namespace + local sourcet, sinkt = {}, {} + _M.sourcet = sourcet + _M.sinkt = sinkt + + _M.BLOCKSIZE = 2048 + + sinkt["close-when-done"] = + function(sock) + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() + end + }, + { + __call = function(self, chunk, err) + if not chunk then + sock:close() + return 1 + else + return sock:send(chunk) + end + end + } + ) + end + sinkt["keep-open"] = function(sock) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function(self, chunk, err) - if chunk then - return sock:send(chunk) - else - return 1 + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - end - } - ) - end + }, + { + __call = function(self, chunk, err) + if chunk then + return sock:send(chunk) + else + return 1 + end + end + } + ) + end sinkt["default"] = sinkt["keep-open"] @@ -179,133 +179,133 @@ local function createSocket() sourcet["by-length"] = function(sock, length) - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if length <= 0 then - return nil + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local size = math.min(socket.BLOCKSIZE, length) - local chunk, err = sock:receive(size) - if err then - return nil, err + }, + { + __call = function() + if length <= 0 then + return nil + end + local size = math.min(socket.BLOCKSIZE, length) + local chunk, err = sock:receive(size) + if err then + return nil, err + end + length = length - string.len(chunk) + return chunk end - length = length - string.len(chunk) - return chunk - end - } - ) - end + } + ) + end sourcet["until-closed"] = function(sock) - local done - return base.setmetatable( - { - getfd = function() - return sock:getfd() - end, - dirty = function() - return sock:dirty() - end - }, - { - __call = function() - if done then - return nil + local done + return base.setmetatable( + { + getfd = function() + return sock:getfd() + end, + dirty = function() + return sock:dirty() end - local chunk, err, partial = sock:receive(socket.BLOCKSIZE) - if not err then - return chunk - elseif err == "closed" then - sock:close() - done = 1 - return partial - else - return nil, err + }, + { + __call = function() + if done then + return nil + end + local chunk, err, partial = sock:receive(socket.BLOCKSIZE) + if not err then + return chunk + elseif err == "closed" then + sock:close() + done = 1 + return partial + else + return nil, err + end end - end - } - ) - end - - sourcet["default"] = sourcet["until-closed"] - - _M.source = _M.choose(sourcet) - - return _M + } + ) + end + + sourcet["default"] = sourcet["until-closed"] + + _M.source = _M.choose(sourcet) + + return _M end local function createJson() - local math = require("math") - local string = require("string") - local table = require("table") - local object = nil - ----------------------------------------------------------------------------- - -- Module declaration - ----------------------------------------------------------------------------- - local json = {} -- Public namespace + local math = require("math") + local string = require("string") + local table = require("table") + local object = nil + ----------------------------------------------------------------------------- + -- Module declaration + ----------------------------------------------------------------------------- + local json = {} -- Public namespace local json_private = {} -- Private namespace - - -- Public constants - json.EMPTY_ARRAY = {} - json.EMPTY_OBJECT = {} - -- Public functions - -- Private functions - local decode_scanArray - local decode_scanComment - local decode_scanConstant - local decode_scanNumber - local decode_scanObject - local decode_scanString - local decode_scanWhitespace - local encodeString - local isArray - local isEncodable - - ----------------------------------------------------------------------------- - -- PUBLIC FUNCTIONS - ----------------------------------------------------------------------------- - --- Encodes an arbitrary Lua object / variable. - -- @param v The Lua object / variable to be JSON encoded. - -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) - function json.encode(v) - -- Handle nil values - if v == nil then - return "null" - end - - local vtype = type(v) - - -- Handle strings - if vtype == "string" then + -- Public constants + json.EMPTY_ARRAY = {} + json.EMPTY_OBJECT = {} + -- Public functions + + -- Private functions + local decode_scanArray + local decode_scanComment + local decode_scanConstant + local decode_scanNumber + local decode_scanObject + local decode_scanString + local decode_scanWhitespace + local encodeString + local isArray + local isEncodable + + ----------------------------------------------------------------------------- + -- PUBLIC FUNCTIONS + ----------------------------------------------------------------------------- + --- Encodes an arbitrary Lua object / variable. + -- @param v The Lua object / variable to be JSON encoded. + -- @return String containing the JSON encoding in internal Lua string format (i.e. not unicode) + function json.encode(v) + -- Handle nil values + if v == nil then + return "null" + end + + local vtype = type(v) + + -- Handle strings + if vtype == "string" then return '"' .. json_private.encodeString(v) .. '"' -- Need to handle encoding in string end - - -- Handle booleans - if vtype == "number" or vtype == "boolean" then + + -- Handle booleans + if vtype == "number" or vtype == "boolean" then return tostring(v) end - - -- Handle tables - if vtype == "table" then - local rval = {} - -- Consider arrays separately - local bArray, maxCount = isArray(v) - if bArray then - for i = 1, maxCount do - table.insert(rval, json.encode(v[i])) - end - else -- An object, not an array + + -- Handle tables + if vtype == "table" then + local rval = {} + -- Consider arrays separately + local bArray, maxCount = isArray(v) + if bArray then + for i = 1, maxCount do + table.insert(rval, json.encode(v[i])) + end + else -- An object, not an array for i, j in pairs(v) do if isEncodable(i) and isEncodable(j) then table.insert(rval, '"' .. json_private.encodeString(i) .. '":' .. json.encode(j)) @@ -317,23 +317,23 @@ local function createJson() else return "{" .. table.concat(rval, ",") .. "}" end - end - - -- Handle null values - if vtype == "function" and v == json.null then + end + + -- Handle null values + if vtype == "function" and v == json.null then return "null" end assert(false, "encode attempt to encode unsupported type " .. vtype .. ":" .. tostring(v)) end - - --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. - -- @param s The string to scan. - -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. - -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, - -- and the position of the first character after - -- the scanned JSON object. - function json.decode(s, startPos) + + --- Decodes a JSON string and returns the decoded value as a Lua data structure / value. + -- @param s The string to scan. + -- @param [startPos] Optional starting position where the JSON string is located. Defaults to 1. + -- @param Lua object, number The object that was scanned, as a Lua table / string / number / boolean or nil, + -- and the position of the first character after + -- the scanned JSON object. + function json.decode(s, startPos) startPos = startPos and startPos or 1 startPos = decode_scanWhitespace(s, startPos) assert(startPos <= string.len(s), "Unterminated JSON encoded object found at position in [" .. s .. "]") @@ -366,18 +366,19 @@ local function createJson() function json.null() return json.null -- so json.null() will also return null ;-) end - ----------------------------------------------------------------------------- - -- Internal, PRIVATE functions. - -- Following a Python-like convention, I have prefixed all these 'PRIVATE' - -- functions with an underscore. - ----------------------------------------------------------------------------- - --- Scans an array from JSON into a Lua object - -- startPos begins at the start of the array. - -- Returns the array and the next starting position - -- @param s The string being scanned. - -- @param startPos The starting position for the scan. - -- @return table, int The scanned array as a table, and the position of the next character to scan. - function decode_scanArray(s, startPos) + + ----------------------------------------------------------------------------- + -- Internal, PRIVATE functions. + -- Following a Python-like convention, I have prefixed all these 'PRIVATE' + -- functions with an underscore. + ----------------------------------------------------------------------------- + --- Scans an array from JSON into a Lua object + -- startPos begins at the start of the array. + -- Returns the array and the next starting position + -- @param s The string being scanned. + -- @param startPos The starting position for the scan. + -- @return table, int The scanned array as a table, and the position of the next character to scan. + function decode_scanArray(s, startPos) local array = {} -- The return value local stringLen = string.len(s) assert( @@ -423,8 +424,8 @@ local function createJson() -- @return object, int The object (true, false or nil) and the position at which the next character should be -- scanned. function decode_scanConstant(s, startPos) - local consts = {["true"] = true, ["false"] = false, ["null"] = nil} - local constNames = {"true", "false", "null"} + local consts = { ["true"] = true, ["false"] = false, ["null"] = nil } + local constNames = { "true", "false", "null" } for i, k in pairs(constNames) do if string.sub(s, startPos, startPos + string.len(k) - 1) == k then @@ -573,7 +574,7 @@ local function createJson() assert( string.find(s, startChar, j + 1), "String decoding failed: missing closing " .. - startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" + startChar .. " at position " .. j .. "(for string at position " .. startPos .. ")" ) return table.concat(t, ""), j + 2 -- END SoniEx2 @@ -649,13 +650,13 @@ local function createJson() if v ~= (t.n or #t) then return false end -- False if n does not hold the number of elements - else -- Else of (k=='n') + else -- Else of (k=='n') if isEncodable(v) then return false end end -- End of (k~='n') - end -- End of k,v not an indexed pair - end -- End of loop across all pairs + end -- End of k,v not an indexed pair + end -- End of loop across all pairs return true, maxIndex end @@ -677,64 +678,64 @@ local debug_server = nil local breakInfoSocket = nil local json = createJson() local LuaDebugger = { - fileMaps = {}, - Run = true, --表示正常运行只检测断点 - StepIn = false, - StepNext = false, - StepOut = false, - breakInfos = {}, - runTimeType = nil, - isHook = true, - pathCachePaths = {}, - isProntToConsole = 1, - isDebugPrint = true, - hookType = "lrc", - stepNextFun = nil, - DebugLuaFie = "", - runLineCount = 0, - --分割字符串缓存 - splitFilePaths = {}, - version="0.9.3", + fileMaps = {}, + Run = true, --表示正常运行只检测断点 + StepIn = false, + StepNext = false, + StepOut = false, + breakInfos = {}, + runTimeType = nil, + isHook = true, + pathCachePaths = {}, + isProntToConsole = 1, + isDebugPrint = true, + hookType = "lrc", + stepNextFun = nil, + DebugLuaFie = "", + runLineCount = 0, + --分割字符串缓存 + splitFilePaths = {}, + version = "0.9.3", serVarLevel = 4 } local debug_hook = nil local _resume = coroutine.resume coroutine.resume = function(co, ...) - if (LuaDebugger.isHook) then + if (LuaDebugger.isHook) then if coroutine.status(co) ~= "dead" then debug.sethook(co, debug_hook, "lrc") - end + end end return _resume(co, ...) end LuaDebugger.event = { - S2C_SetBreakPoints = 1, - C2S_SetBreakPoints = 2, - S2C_RUN = 3, - C2S_HITBreakPoint = 4, - S2C_ReqVar = 5, - C2S_ReqVar = 6, - --单步跳过请求 - S2C_NextRequest = 7, - --单步跳过反馈 - C2S_NextResponse = 8, - -- 单步跳过 结束 没有下一步 - C2S_NextResponseOver = 9, - --单步跳入 - S2C_StepInRequest = 10, - C2S_StepInResponse = 11, - --单步跳出 - S2C_StepOutRequest = 12, - --单步跳出返回 - C2S_StepOutResponse = 13, - --打印 - C2S_LuaPrint = 14, - S2C_LoadLuaScript = 16, - C2S_SetSocketName = 17, - C2S_LoadLuaScript = 18, - C2S_DebugXpCall = 20, - S2C_DebugClose = 21, + S2C_SetBreakPoints = 1, + C2S_SetBreakPoints = 2, + S2C_RUN = 3, + C2S_HITBreakPoint = 4, + S2C_ReqVar = 5, + C2S_ReqVar = 6, + --单步跳过请求 + S2C_NextRequest = 7, + --单步跳过反馈 + C2S_NextResponse = 8, + -- 单步跳过 结束 没有下一步 + C2S_NextResponseOver = 9, + --单步跳入 + S2C_StepInRequest = 10, + C2S_StepInResponse = 11, + --单步跳出 + S2C_StepOutRequest = 12, + --单步跳出返回 + C2S_StepOutResponse = 13, + --打印 + C2S_LuaPrint = 14, + S2C_LoadLuaScript = 16, + C2S_SetSocketName = 17, + C2S_LoadLuaScript = 18, + C2S_DebugXpCall = 20, + S2C_DebugClose = 21, S2C_SerVar = 24, C2S_SerVar = 25, S2C_ReLoadFile = 26, @@ -742,27 +743,27 @@ LuaDebugger.event = { } --@region print function print(...) - if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then + if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 1} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 1 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end function luaIdePrintWarn(...) @@ -771,46 +772,48 @@ function luaIdePrintWarn(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 2} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 2 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end + function luaIdePrintErr(...) if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 3) then debugger_print(...) end if (LuaDebugger.isProntToConsole == 1 or LuaDebugger.isProntToConsole == 2) then if (debug_server) then - local arg = {...} --这里的...和{}符号中间需要有空格号,否则会出错 + local arg = { ... } --这里的...和{}符号中间需要有空格号,否则会出错 local str = "" if (#arg == 0) then - arg = {"nil"} - end - for k, v in pairs(arg) do - str = str .. tostring(v) .. "\t" - end - local sendMsg = { - event = LuaDebugger.event.C2S_LuaPrint, - data = {msg = ZZBase64.encode(str), type = 3} - } - local sendStr = json.encode(sendMsg) - debug_server:send(sendStr .. "__debugger_k0204__") - end - end + arg = { "nil" } + end + for k, v in pairs(arg) do + str = str .. tostring(v) .. "\t" + end + local sendMsg = { + event = LuaDebugger.event.C2S_LuaPrint, + data = { msg = ZZBase64.encode(str), type = 3 } + } + local sendStr = json.encode(sendMsg) + debug_server:send(sendStr .. "__debugger_k0204__") + end + end end + --@endregion --@region 辅助方法 @@ -841,23 +844,23 @@ local function debugger_convertParentDir(dir) end end -local function debugger_getFilePathInfo(file) - local fileName = nil +local function debugger_getFilePathInfo(file) + local fileName = nil local dir = nil file = file:gsub("/.\\", "/") - file = file:gsub("\\", "/") - file = file:gsub("//", "/") - + file = file:gsub("\\", "/") + file = file:gsub("//", "/") - if file:find("@") == 1 then + + if file:find("@") == 1 then file = file:sub(2) - end - local findex = file:find("%./") - if (findex == 1) then + end + local findex = file:find("%./") + if (findex == 1) then file = file:sub(3) end - file = debugger_convertParentDir(file) + file = debugger_convertParentDir(file) local fileLength = string.len(file) local suffixNames = { ".lua", @@ -886,8 +889,8 @@ local function debugger_getFilePathInfo(file) end local fileNameStartIndex = debugger_lastIndex(file, "/") if (fileNameStartIndex) then - fileName = string.sub(file, fileNameStartIndex + 1) - + fileName = string.sub(file, fileNameStartIndex + 1) + dir = string.sub(file, 1, fileNameStartIndex) file = dir .. fileName else @@ -898,12 +901,12 @@ local function debugger_getFilePathInfo(file) else dir = string.sub(file, 1, fileNameStartIndex) dir = dir:gsub("%.", "/") - fileName = string.sub(file, fileNameStartIndex + 1) - file = dir .. fileName + fileName = string.sub(file, fileNameStartIndex + 1) + file = dir .. fileName end - end + end - return file, dir, fileName + return file, dir, fileName end --@endregion @@ -915,25 +918,25 @@ end local function debugger_strSplit(input, delimiter) - input = tostring(input) - delimiter = tostring(delimiter) - if (delimiter == "") then + input = tostring(input) + delimiter = tostring(delimiter) + if (delimiter == "") then return false end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(input, delimiter, pos, true) - end do - table.insert(arr, string.sub(input, pos, st - 1)) - pos = sp + 1 - end - table.insert(arr, string.sub(input, pos)) - return arr + end do + table.insert(arr, string.sub(input, pos, st - 1)) + pos = sp + 1 + end + table.insert(arr, string.sub(input, pos)) + return arr end local function debugger_strTrim(input) - input = string.gsub(input, "^[ \t\n\r]+", "") - return string.gsub(input, "[ \t\n\r]+$", "") + input = string.gsub(input, "^[ \t\n\r]+", "") + return string.gsub(input, "[ \t\n\r]+$", "") end local function debugger_dump(value, desciption, nesting) if type(nesting) ~= "number" then @@ -1005,27 +1008,24 @@ local function debugger_valueToString(v) local vtype = type(v) local vstr = nil if (vtype == "userdata") then - if (LuaDebugger.isFoxGloryProject ) then - - return "userdata",vtype - + if (LuaDebugger.isFoxGloryProject) then + return "userdata", vtype else return tostring(v), vtype end elseif (vtype == "table" or vtype == "function" or vtype == "boolean") then local value = vtype - xpcall(function() - if(LuaDebugger.isFoxGloryProject) then + xpcall(function() + if (LuaDebugger.isFoxGloryProject) then value = vtype else value = tostring(v) end - - end,function() + end, function() value = vtype end) return value, vtype - elseif (vtype == "number" or vtype == "string" ) then + elseif (vtype == "number" or vtype == "string") then return v, vtype else return tostring(v), vtype @@ -1033,12 +1033,12 @@ local function debugger_valueToString(v) end local function debugger_setVarInfo(name, value) local valueStr, valueType = debugger_valueToString(value) - local nameStr,nameType = debugger_valueToString(name) - if(valueStr == nil) then + local nameStr, nameType = debugger_valueToString(name) + if (valueStr == nil) then valueStr = valueType end local valueInfo = { - name =nameStr, + name = nameStr, valueType = valueType, valueStr = ZZBase64.encode(valueStr) } @@ -1047,283 +1047,282 @@ local function debugger_setVarInfo(name, value) end local function debugger_getvalue(f) - local i = 1 - local locals = {} - -- get locals - while true do - local name, value = debug.getlocal(f, i) - if not name then + local i = 1 + local locals = {} + -- get locals + while true do + local name, value = debug.getlocal(f, i) + if not name then break end if (name ~= "(*temporary)") then - locals[name] = value - end - i = i + 1 - end - local func = getinfo(f, "f").func - i = 1 - local ups = {} - while func do -- check for func as it may be nil for tail calls - local name, value = debug.getupvalue(func, i) - if not name then + locals[name] = value + end + i = i + 1 + end + local func = getinfo(f, "f").func + i = 1 + local ups = {} + while func do -- check for func as it may be nil for tail calls + local name, value = debug.getupvalue(func, i) + if not name then break end if (name == "_ENV") then - ups["_ENV_"] = value - else - ups[name] = value - end - i = i + 1 - end + ups["_ENV_"] = value + else + ups[name] = value + end + i = i + 1 + end - return {locals = locals, ups = ups} + return { locals = locals, ups = ups } end --获取堆栈 debugger_stackInfo = function(ignoreCount, event) - local datas = {} - local stack = {} - local varInfos = {} - local funcs = {} - local index = 0 - for i = ignoreCount, 100 do - local source = getinfo(i) - local isadd = true - if (i == ignoreCount) then - local file = source.source - if (file:find(LuaDebugger.DebugLuaFie)) then - return - end - if (file == "=[C]") then - isadd = false - end - end - if not source then - break - end - if (isadd) then - local fullName, dir, fileName = debugger_getFilePathInfo(source.source) - local info = { - src = fullName, - scoreName = source.name, - currentline = source.currentline, - linedefined = source.linedefined, - what = source.what, - nameWhat = source.namewhat - } - index = i - local vars = debugger_getvalue(i + 1) - table.insert(stack, info) - table.insert(varInfos, vars) - table.insert(funcs, source.func) - end - if source.what == "main" then - break + local datas = {} + local stack = {} + local varInfos = {} + local funcs = {} + local index = 0 + for i = ignoreCount, 100 do + local source = getinfo(i) + local isadd = true + if (i == ignoreCount) then + local file = source.source + if (file:find(LuaDebugger.DebugLuaFie)) then + return + end + if (file == "=[C]") then + isadd = false + end + end + if not source then + break + end + if (isadd) then + local fullName, dir, fileName = debugger_getFilePathInfo(source.source) + local info = { + src = fullName, + scoreName = source.name, + currentline = source.currentline, + linedefined = source.linedefined, + what = source.what, + nameWhat = source.namewhat + } + index = i + local vars = debugger_getvalue(i + 1) + table.insert(stack, info) + table.insert(varInfos, vars) + table.insert(funcs, source.func) + end + if source.what == "main" then + break + end end - end - local stackInfo = {stack = stack, vars = varInfos, funcs = funcs} - local data = { - stack = stackInfo.stack, - vars = stackInfo.vars, - funcs = stackInfo.funcs, - event = event, - funcsLength = #stackInfo.funcs, - upFunc = getinfo(ignoreCount - 3, "f").func - } + local stackInfo = { stack = stack, vars = varInfos, funcs = funcs } + local data = { + stack = stackInfo.stack, + vars = stackInfo.vars, + funcs = stackInfo.funcs, + event = event, + funcsLength = #stackInfo.funcs, + upFunc = getinfo(ignoreCount - 3, "f").func + } - return data -end + return data + end --==============================工具方法 end====================================================== --===========================点断信息================================================== --根据不同的游戏引擎进行定时获取断点信息 --CCDirector:sharedDirector():getScheduler() local debugger_setBreak = nil local function debugger_receiveDebugBreakInfo() - if(not jit) then - if(_VERSION)then - print("当前lua版本为: ".._VERSION.." 请使用 -----LuaDebug.lua----- 进行调试!") - else - print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") - end - end - if (breakInfoSocket) then + if (not jit) then + if (_VERSION) then + print("当前lua版本为: " .. _VERSION .. " 请使用 -----LuaDebug.lua----- 进行调试!") + else + print("当前为lua版本,请使用-----LuaDebug.lua-----进行调试!") + end + end + if (breakInfoSocket) then local msg, status = breakInfoSocket:receive() - if(LuaDebugger.isLaunch == true and status == "closed") then + if (LuaDebugger.isLaunch == true and status == "closed") then os.exit() end - if (msg) then - local netData = json.decode(msg) - if netData.event == LuaDebugger.event.S2C_SetBreakPoints then - debugger_setBreak(netData.data) - elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then - LuaDebugger.loadScriptBody = netData.data + if (msg) then + local netData = json.decode(msg) + if netData.event == LuaDebugger.event.S2C_SetBreakPoints then + debugger_setBreak(netData.data) + elseif netData.event == LuaDebugger.event.S2C_LoadLuaScript then + LuaDebugger.loadScriptBody = netData.data debugger_exeLuaString() - debugger_sendMsg(breakInfoSocket,LuaDebugger.event.C2S_LoadLuaScript,LuaDebugger.loadScriptBody) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) elseif netData.event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.reLoadFileBody = netData.data LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) LuaDebugger.reLoadFileBody.script = nil - + debugger_sendMsg( breakInfoSocket, LuaDebugger.event.C2S_ReLoadFile, { stack = LuaDebugger.reLoadFileBody - + } - ) - end - end - end + ) + end + end + end end local function splitFilePath(path) - if (LuaDebugger.splitFilePaths[path]) then - return LuaDebugger.splitFilePaths[path] - end - local pos, arr = 0, {} - -- for each divider found - for st, sp in function() + if (LuaDebugger.splitFilePaths[path]) then + return LuaDebugger.splitFilePaths[path] + end + local pos, arr = 0, {} + -- for each divider found + for st, sp in function() return string.find(path, "/", pos, true) - end do - local pathStr = string.sub(path, pos, st - 1) - table.insert(arr, pathStr) - pos = sp + 1 - end - local pathStr = string.sub(path, pos) - table.insert(arr, pathStr) - LuaDebugger.splitFilePaths[path] = arr - return arr -end -debugger_setBreak = - function(datas) - local breakInfos = LuaDebugger.breakInfos - for i, data in ipairs(datas) do - data.fileName = string.lower(data.fileName) - data.serverPath = string.lower(data.serverPath) - local breakInfo = breakInfos[data.fileName] - if (not breakInfo) then - breakInfos[data.fileName] = {} - breakInfo = breakInfos[data.fileName] - end - if (not data.breakDatas or #data.breakDatas == 0) then - breakInfo[data.serverPath] = nil - else - local fileBreakInfo = breakInfo[data.serverPath] - if (not fileBreakInfo) then - fileBreakInfo = { - pathNames = splitFilePath(data.serverPath), - --命中次數判斷計數器 - hitCounts = {} - } - breakInfo[data.serverPath] = fileBreakInfo - end - local lineInfos = {} - for li, breakData in ipairs(data.breakDatas) do - lineInfos[breakData.line] = breakData - if (breakData.hitCondition and breakData.hitCondition ~= "") then - breakData.hitCondition = tonumber(breakData.hitCondition) - else - breakData.hitCondition = 0 - end - if (not fileBreakInfo.hitCounts[breakData.line]) then - fileBreakInfo.hitCounts[breakData.line] = 0 - end - end - fileBreakInfo.lines = lineInfos - --這裡添加命中次數判斷 - for line, count in pairs(fileBreakInfo.hitCounts) do - if (not lineInfos[line]) then - fileBreakInfo.hitCounts[line] = nil - end - end - end - local count = 0 - for i, linesInfo in pairs(breakInfo) do - count = count + 1 - end - if (count == 0) then - breakInfos[data.fileName] = nil - end - end - --debugger_dump(breakInfos, "breakInfos", 6) - --检查是否需要断点 - local isHook = false - for k, v in pairs(breakInfos) do - isHook = true - break - end - - --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 - if (isHook) then - if (not LuaDebugger.isHook) then - debug.sethook(debug_hook, "lrc") - end - LuaDebugger.isHook = true - else - if (LuaDebugger.isHook) then - debug.sethook() - end - LuaDebugger.isHook = false - end + end do + local pathStr = string.sub(path, pos, st - 1) + table.insert(arr, pathStr) + pos = sp + 1 + end + local pathStr = string.sub(path, pos) + table.insert(arr, pathStr) + LuaDebugger.splitFilePaths[path] = arr + return arr end +debugger_setBreak = + function(datas) + local breakInfos = LuaDebugger.breakInfos + for i, data in ipairs(datas) do + data.fileName = string.lower(data.fileName) + data.serverPath = string.lower(data.serverPath) + local breakInfo = breakInfos[data.fileName] + if (not breakInfo) then + breakInfos[data.fileName] = {} + breakInfo = breakInfos[data.fileName] + end + if (not data.breakDatas or #data.breakDatas == 0) then + breakInfo[data.serverPath] = nil + else + local fileBreakInfo = breakInfo[data.serverPath] + if (not fileBreakInfo) then + fileBreakInfo = { + pathNames = splitFilePath(data.serverPath), + --命中次數判斷計數器 + hitCounts = {} + } + breakInfo[data.serverPath] = fileBreakInfo + end + local lineInfos = {} + for li, breakData in ipairs(data.breakDatas) do + lineInfos[breakData.line] = breakData + if (breakData.hitCondition and breakData.hitCondition ~= "") then + breakData.hitCondition = tonumber(breakData.hitCondition) + else + breakData.hitCondition = 0 + end + if (not fileBreakInfo.hitCounts[breakData.line]) then + fileBreakInfo.hitCounts[breakData.line] = 0 + end + end + fileBreakInfo.lines = lineInfos + --這裡添加命中次數判斷 + for line, count in pairs(fileBreakInfo.hitCounts) do + if (not lineInfos[line]) then + fileBreakInfo.hitCounts[line] = nil + end + end + end + local count = 0 + for i, linesInfo in pairs(breakInfo) do + count = count + 1 + end + if (count == 0) then + breakInfos[data.fileName] = nil + end + end + --debugger_dump(breakInfos, "breakInfos", 6) + --检查是否需要断点 + local isHook = false + for k, v in pairs(breakInfos) do + isHook = true + break + end + + --这样做的原因是为了最大限度的使手机调试更加流畅 注意这里会连续的进行n次 + if (isHook) then + if (not LuaDebugger.isHook) then + debug.sethook(debug_hook, "lrc") + end + LuaDebugger.isHook = true + else + if (LuaDebugger.isHook) then + debug.sethook() + end + LuaDebugger.isHook = false + end + end local function debugger_checkFileIsBreak(fileName) - return LuaDebugger.breakInfos[fileName] + return LuaDebugger.breakInfos[fileName] end --=====================================断点信息 end ---------------------------------------------- local controller_host = "192.168.1.102" local controller_port = 7003 debugger_sendMsg = function(serverSocket, eventName, data) - local sendMsg = { - event = eventName, - data = data - } - local sendStr = json.encode(sendMsg) - serverSocket:send(sendStr .. "__debugger_k0204__") + local sendMsg = { + event = eventName, + data = data + } + local sendStr = json.encode(sendMsg) + serverSocket:send(sendStr .. "__debugger_k0204__") end -function debugger_conditionStr(condition, vars, callBack) - local function loadScript() - local currentTabble = {} - - local locals = vars[1].locals - local ups = vars[1].ups - if (ups) then - for k, v in pairs(ups) do - currentTabble[k] = v - end - end - - if (locals) then - for k, v in pairs(locals) do - currentTabble[k] = v - end - end - setmetatable(currentTabble, {__index = _G}) - local fun = loadstring("return " .. condition) - setfenv(fun, currentTabble) - return fun() - end - local status, - msg = - xpcall( - loadScript, - function(error) - print(error) +function debugger_conditionStr(condition, vars, callBack) + local function loadScript() + local currentTabble = {} + + local locals = vars[1].locals + local ups = vars[1].ups + if (ups) then + for k, v in pairs(ups) do + currentTabble[k] = v + end end - ) + + if (locals) then + for k, v in pairs(locals) do + currentTabble[k] = v + end + end + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring("return " .. condition) + setfenv(fun, currentTabble) + return fun() + end + local status, + msg = + xpcall( + loadScript, + function(error) + print(error) + end + ) if (status and msg) then callBack() end end + --执行lua字符串 debugger_exeLuaString = function() - local function loadScript() - local script = LuaDebugger.loadScriptBody.script if (LuaDebugger.loadScriptBody.isBreak) then - local currentTabble = {_G = _G} + local currentTabble = { _G = _G } local frameId = LuaDebugger.loadScriptBody.frameId frameId = frameId local func = LuaDebugger.currentDebuggerData.funcs[frameId] @@ -1336,8 +1335,8 @@ debugger_exeLuaString = function() for k, v in pairs(locals) do currentTabble[k] = v end - setmetatable(currentTabble, {__index = _G}) - + setmetatable(currentTabble, { __index = _G }) + local fun = loadstring(script) setfenv(fun, currentTabble) fun() @@ -1347,54 +1346,51 @@ debugger_exeLuaString = function() end end local status, - msg = + msg = xpcall( - loadScript, - function(error) - - -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) - end - ) - LuaDebugger.loadScriptBody.script = nil + loadScript, + function(error) + -- debugger_sendMsg(debug_server, LuaDebugger.event.C2S_LoadLuaScript, LuaDebugger.loadScriptBody) + end + ) + LuaDebugger.loadScriptBody.script = nil if (LuaDebugger.loadScriptBody.isBreak) then - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack - end + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event + .C2S_HITBreakPoint) + LuaDebugger.loadScriptBody.stack = LuaDebugger.currentDebuggerData.stack + end LuaDebugger.loadScriptBody.complete = true - end --@region 调试中修改变量值 --根据key 值在 value 查找 -local function debugger_getTablekey(key,keyType,value) - if(keyType == -1) then +local function debugger_getTablekey(key, keyType, value) + if (keyType == -1) then return key - elseif(keyType == 1) then + elseif (keyType == 1) then return tonumber(key) - elseif(keyType == 2) then + elseif (keyType == 2) then local valueKey = nil - for k,v in pairs(value) do + for k, v in pairs(value) do local nameType = type(k) - if(nameType == "userdata" or nameType == "table") then + if (nameType == "userdata" or nameType == "table") then if (not LuaDebugger.isFoxGloryProject) then valueKey = tostring(k) - if(key == valueKey) then + if (key == valueKey) then return k end break end end end - end end local function debugger_setVarValue(server, data) - local newValue = nil - local level = LuaDebugger.serVarLevel+LuaDebugger.setVarBody.frameId + local level = LuaDebugger.serVarLevel + LuaDebugger.setVarBody.frameId local firstKeyName = data.keys[1] --@region vars check local localValueChangeIndex = -1 @@ -1409,7 +1405,7 @@ local function debugger_setVarValue(server, data) if not name then break end - if(firstKeyName == name) then + if (firstKeyName == name) then localValueChangeIndex = i oldValue = value end @@ -1423,11 +1419,11 @@ local function debugger_setVarValue(server, data) local ups = {} while func do -- check for func as it may be nil for tail calls local name, value = debug.getupvalue(func, i) - + if not name then break end - if(localValueChangeIndex == -1 and firstKeyName == name) then + if (localValueChangeIndex == -1 and firstKeyName == name) then upValueFun = func oldValue = value upValueChangeIndex = i @@ -1439,9 +1435,9 @@ local function debugger_setVarValue(server, data) end i = i + 1 end ---@endregion - local vars = {locals = locals, ups = ups} - + --@endregion + local vars = { locals = locals, ups = ups } + local function loadScript() local currentTabble = {} local locals = vars.locals @@ -1457,58 +1453,56 @@ local function debugger_setVarValue(server, data) currentTabble[k] = v end end - setmetatable(currentTabble, {__index = _G}) + setmetatable(currentTabble, { __index = _G }) local fun = loadstring("return " .. data.value) setfenv(fun, currentTabble) newValue = fun() end local status, - msg = + msg = xpcall( - loadScript, - function(error) - print(error, "============================") - end - ) - + loadScript, + function(error) + print(error, "============================") + end + ) + local i = 1 - + -- local 查找并替换 local keyLength = #data.keys - - if(keyLength == 1) then - if(localValueChangeIndex ~= -1) then - + + if (keyLength == 1) then + if (localValueChangeIndex ~= -1) then debug.setlocal(level, localValueChangeIndex, newValue) - elseif(upValueFun ~= nil) then - debug.setupvalue( upValueFun, upValueChangeIndex, newValue ) + elseif (upValueFun ~= nil) then + debug.setupvalue(upValueFun, upValueChangeIndex, newValue) else --全局变量查找 - if(_G[firstKeyName]) then + if (_G[firstKeyName]) then _G[firstKeyName] = newValue end end else - if(not oldValue) then - if(_G[firstKeyName]) then + if (not oldValue) then + if (_G[firstKeyName]) then oldValue = _G[firstKeyName] end end local tempValue = oldValue - for i=2,keyLength-1 do - if(tempValue) then - oldValue = oldValue[debugger_getTablekey(data.keys[i],data.numberTypes[i],oldValue)] + for i = 2, keyLength - 1 do + if (tempValue) then + oldValue = oldValue[debugger_getTablekey(data.keys[i], data.numberTypes[i], oldValue)] end end - if(tempValue) then - oldValue[debugger_getTablekey(data.keys[keyLength],data.numberTypes[keyLength],oldValue)] = newValue + if (tempValue) then + oldValue[debugger_getTablekey(data.keys[keyLength], data.numberTypes[keyLength], oldValue)] = newValue end end - local varInfo = debugger_setVarInfo(data.varName, newValue) + local varInfo = debugger_setVarInfo(data.varName, newValue) data.varInfo = varInfo - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 LuaDebugger.currentDebuggerData = debugger_stackInfo(LuaDebugger.serVarLevel, LuaDebugger.event.C2S_HITBreakPoint) - end --@endregion @@ -1518,107 +1512,107 @@ end --调试修改变量值统一的 _resume checkSetVar = function() - if (LuaDebugger.isSetVar) then - LuaDebugger.isSetVar = false - debugger_setVarValue(debug_server,LuaDebugger.setVarBody) - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.setVarBody) - xpcall( - checkSetVar, - function(error) - print("设置变量", error) - end - ) - elseif(LuaDebugger.isLoadLuaScript) then - LuaDebugger.isLoadLuaScript = false - debugger_exeLuaString() - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("执行代码", error) - end - ) - elseif(LuaDebugger.isReLoadFile) then - LuaDebugger.isReLoadFile = false - LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) - print("重载结果:",LuaDebugger.reLoadFileBody.isReLoad) - LuaDebugger.reLoadFileBody.script = nil - LuaDebugger.serVarLevel = LuaDebugger.serVarLevel+1 - _resume(coro_debugger, LuaDebugger.reLoadFileBody) - xpcall( - checkSetVar, - function(error) - print("重新加载文件", error) - end - ) + if (LuaDebugger.isSetVar) then + LuaDebugger.isSetVar = false + debugger_setVarValue(debug_server, LuaDebugger.setVarBody) + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.setVarBody) + xpcall( + checkSetVar, + function(error) + print("设置变量", error) + end + ) + elseif (LuaDebugger.isLoadLuaScript) then + LuaDebugger.isLoadLuaScript = false + debugger_exeLuaString() + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("执行代码", error) + end + ) + elseif (LuaDebugger.isReLoadFile) then + LuaDebugger.isReLoadFile = false + LuaDebugger.reLoadFileBody.isReLoad = debugger_reLoadFile(LuaDebugger.reLoadFileBody) + print("重载结果:", LuaDebugger.reLoadFileBody.isReLoad) + LuaDebugger.reLoadFileBody.script = nil + LuaDebugger.serVarLevel = LuaDebugger.serVarLevel + 1 + _resume(coro_debugger, LuaDebugger.reLoadFileBody) + xpcall( + checkSetVar, + function(error) + print("重新加载文件", error) + end + ) + end end -end - + local function getSource(source) - source = string.lower(source) + source = string.lower(source) if (LuaDebugger.pathCachePaths[source]) then - LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] - return LuaDebugger.pathCachePaths[source] - end + LuaDebugger.currentLineFile = LuaDebugger.pathCachePaths[source] + return LuaDebugger.pathCachePaths[source] + end - local fullName, dir, fileName = debugger_getFilePathInfo(source) - LuaDebugger.currentLineFile = fullName - LuaDebugger.pathCachePaths[source] = fileName + local fullName, dir, fileName = debugger_getFilePathInfo(source) + LuaDebugger.currentLineFile = fullName + LuaDebugger.pathCachePaths[source] = fileName - return fileName + return fileName end local function debugger_GeVarInfoBytUserData(server, var) - local fileds = LuaDebugTool.getUserDataInfo(var) - - local varInfos = {} + local fileds = LuaDebugTool.getUserDataInfo(var) - - --c# vars - for i = 1, fileds.Count do - local filed = fileds[i - 1] - local valueInfo = { - name = filed.name, - valueType = filed.valueType, - valueStr = ZZBase64.encode(filed.valueStr), - isValue = filed.isValue, - csharp = true - } - - table.insert(varInfos, valueInfo) - end - return varInfos -end + local varInfos = {} + + + --c# vars + for i = 1, fileds.Count do + local filed = fileds[i - 1] + local valueInfo = { + name = filed.name, + valueType = filed.valueType, + valueStr = ZZBase64.encode(filed.valueStr), + isValue = filed.isValue, + csharp = true + } + + table.insert(varInfos, valueInfo) + end + return varInfos +end local function debugger_getValueByScript(value, script) - local val = nil - local status, - msg = - xpcall( - function() - local fun = loadstring("return " .. script) - setfenv(fun, value) - val = fun() - end, - function(error) - print(error, "====>") - val = nil - end - ) + local val = nil + local status, + msg = + xpcall( + function() + local fun = loadstring("return " .. script) + setfenv(fun, value) + val = fun() + end, + function(error) + print(error, "====>") + val = nil + end + ) - return val + return val end -local function debugger_getVarByKeys(value, keys, index) - local str = "" - local keyLength = #keys - for i = index, keyLength do - local key = keys[i] - if (key == "[metatable]") then - else - if (i == index) then +local function debugger_getVarByKeys(value, keys, index) + local str = "" + local keyLength = #keys + for i = index, keyLength do + local key = keys[i] + if (key == "[metatable]") then + else + if (i == index) then if (string.find(key, "%.")) then if (str == "") then i = index + 1 @@ -1630,10 +1624,10 @@ local function debugger_getVarByKeys(value, keys, index) return debugger_getVarByKeys(value, keys, i) else - str = key - end - else - if (string.find(key, "%[")) then + str = key + end + else + if (string.find(key, "%[")) then str = str .. key elseif (type(key) == "string") then if (string.find(key, "table:") or string.find(key, "userdata:") or string.find(key, "function:")) then @@ -1712,7 +1706,7 @@ end local function debugger_searchVarByKeys(value, keys, searckKeys) local index, val = debugger_getVarByKeys(value, searckKeys, 1) - if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then + if (not LuaDebugTool or not LuaDebugTool.getCSharpValue or type(LuaDebugTool.getCSharpValue) ~= "function") then return index, val end if (val) then @@ -1745,7 +1739,6 @@ end return ]] local function debugger_getmetatable(value, metatable, vinfos, server, variablesReference, debugSpeedIndex, metatables) - for i, mtable in ipairs(metatables) do if (metatable == mtable) then return vinfos @@ -1794,14 +1787,13 @@ local function debugger_getmetatable(value, metatable, vinfos, server, variables end end end - + local m = getmetatable(metatable) if (m) then return debugger_getmetatable(value, m, vinfos, server, variablesReference, debugSpeedIndex, metatables) else return vinfos end - end local function debugger_sendTableField(luatable, vinfos, server, variablesReference, debugSpeedIndex, valueType) if (valueType == "userdata") then @@ -1840,12 +1832,12 @@ local function debugger_sendTableValues(value, server, variablesReference, debug local valueType = type(value) local userDataInfos = {} local m = nil - + if (valueType == "userdata") then m = getmetatable(value) - + vinfos = debugger_sendTableField(value, vinfos, server, variablesReference, debugSpeedIndex, valueType) - + if (LuaDebugTool) then local varInfos = debugger_GeVarInfoBytUserData(server, value, variablesReference, debugSpeedIndex) @@ -1874,7 +1866,6 @@ local function debugger_sendTableValues(value, server, variablesReference, debug vinfos = {} end end - end else m = getmetatable(value) @@ -1898,56 +1889,55 @@ end --获取lua 变量的方法 local function debugger_getBreakVar(body, server) - local variablesReference = body.variablesReference - local debugSpeedIndex = body.debugSpeedIndex - local vinfos = {} - local function exe() - local frameId = body.frameId + local variablesReference = body.variablesReference + local debugSpeedIndex = body.debugSpeedIndex + local vinfos = {} + local function exe() + local frameId = body.frameId local type_ = body.type local keys = body.keys - --找到对应的var - local vars = nil - if (type_ == 1) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.locals - elseif (type_ == 2) then - vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] - vars = vars.ups - elseif (type_ == 3) then - vars = _G - end - if (#keys == 0) then - debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) - return - end - local index, value = debugger_searchVarByKeys(vars, keys, keys) - if (value) then - local valueType = type(value) + --找到对应的var + local vars = nil + if (type_ == 1) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.locals + elseif (type_ == 2) then + vars = LuaDebugger.currentDebuggerData.vars[frameId + 1] + vars = vars.ups + elseif (type_ == 3) then + vars = _G + end + if (#keys == 0) then + debugger_sendTableValues(vars, server, variablesReference, debugSpeedIndex) + return + end + local index, value = debugger_searchVarByKeys(vars, keys, keys) + if (value) then + local valueType = type(value) if (valueType == "table" or valueType == "userdata") then - - debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) - else + debugger_sendTableValues(value, server, variablesReference, debugSpeedIndex) + else if (valueType == "function") then - if(LuaDebugger.isFoxGloryProject) then - value = "function" + if (LuaDebugger.isFoxGloryProject) then + value = "function" else value = tostring(value) end - end - debugger_sendMsg( + end + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { - variablesReference = variablesReference, - debugSpeedIndex = debugSpeedIndex, - vars = ZZBase64.encode(value), - isComplete = 1, - varType = valueType - } + variablesReference = variablesReference, + debugSpeedIndex = debugSpeedIndex, + vars = ZZBase64.encode(value), + isComplete = 1, + varType = valueType + } ) - end - else - debugger_sendMsg( + end + else + debugger_sendMsg( server, LuaDebugger.event.C2S_ReqVar, { @@ -1958,9 +1948,9 @@ local function debugger_getBreakVar(body, server) varType = "nil" } ) - end - end - xpcall( + end + end + xpcall( exe, function(error) -- print("获取变量错误 错误消息-----------------") @@ -1987,64 +1977,62 @@ local function debugger_getBreakVar(body, server) ) end local function ResetDebugInfo() - LuaDebugger.Run = false - LuaDebugger.StepIn = false - LuaDebugger.StepNext = false - LuaDebugger.StepOut = false - + LuaDebugger.Run = false + LuaDebugger.StepIn = false + LuaDebugger.StepNext = false + LuaDebugger.StepOut = false end local function debugger_loop(server) - server = debug_server - --命令 - local command - local eval_env = {} - local arg - while true do - local line, status = server:receive() - if (status == "closed") then - if(LuaDebugger.isLaunch) then + server = debug_server + --命令 + local command + local eval_env = {} + local arg + while true do + local line, status = server:receive() + if (status == "closed") then + if (LuaDebugger.isLaunch) then os.exit() else debug.sethook() coroutine.yield() end - end - if (line) then - local netData = json.decode(line) - local event = netData.event + end + if (line) then + local netData = json.decode(line) + local event = netData.event local body = netData.data if (event == LuaDebugger.event.S2C_DebugClose) then - if(LuaDebugger.isLaunch) then - os.exit() - else - debug.sethook() - coroutine.yield() - end - - elseif event == LuaDebugger.event.S2C_SetBreakPoints then - --设置断点信息 - local function setB() - debugger_setBreak(body) - end - xpcall( + if (LuaDebugger.isLaunch) then + os.exit() + else + debug.sethook() + coroutine.yield() + end + elseif event == LuaDebugger.event.S2C_SetBreakPoints then + --设置断点信息 + local function setB() + debugger_setBreak(body) + end + xpcall( setB, function(error) print(error) end ) - elseif event == LuaDebugger.event.S2C_RUN then --开始运行 - LuaDebugger.runTimeType = body.runTimeType - LuaDebugger.isProntToConsole = body.isProntToConsole + elseif event == LuaDebugger.event.S2C_RUN then --开始运行 + LuaDebugger.runTimeType = body.runTimeType + LuaDebugger.isProntToConsole = body.isProntToConsole LuaDebugger.isFoxGloryProject = body.isFoxGloryProject LuaDebugger.isLaunch = body.isLaunch - ResetDebugInfo() - LuaDebugger.currentDebuggerData = nil - LuaDebugger.Run = true + ResetDebugInfo() + LuaDebugger.currentDebuggerData = nil + LuaDebugger.Run = true LuaDebugger.tempRunFlag = true - LuaDebugger.currentLine= nil - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - LuaDebugger.currentDebuggerData = data + LuaDebugger.currentLine = nil + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + LuaDebugger.currentDebuggerData = data debugger_sendMsg( server, data.event, @@ -2052,58 +2040,58 @@ local function debugger_loop(server) stack = data.stack } ) - elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 - --请求数据信息 - debugger_getBreakVar(body, server) - elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 - ResetDebugInfo() - LuaDebugger.StepNext = true - --设置当前文件名和当前行数 - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif event == LuaDebugger.event.S2C_ReqVar then -- 获取变量信息 + --请求数据信息 + debugger_getBreakVar(body, server) + elseif event == LuaDebugger.event.S2C_NextRequest then -- 设置单步跳过 + ResetDebugInfo() + LuaDebugger.StepNext = true + --设置当前文件名和当前行数 + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { stack = data.stack } ) - elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 - --单步跳入 - ResetDebugInfo() - LuaDebugger.StepIn = true - - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + elseif (event == LuaDebugger.event.S2C_StepInRequest) then --单步跳入 + --单步跳入 + ResetDebugInfo() + LuaDebugger.StepIn = true + + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif (event == LuaDebugger.event.S2C_StepOutRequest) then - --单步跳出 - ResetDebugInfo() - LuaDebugger.StepOut = true - local data = coroutine.yield() - LuaDebugger.serVarLevel = 4 - --重置调试信息 - LuaDebugger.currentDebuggerData = data - debugger_sendMsg( + stack = data.stack, + eventType = data.eventType + } + ) + elseif (event == LuaDebugger.event.S2C_StepOutRequest) then + --单步跳出 + ResetDebugInfo() + LuaDebugger.StepOut = true + local data = coroutine.yield() + LuaDebugger.serVarLevel = 4 + --重置调试信息 + LuaDebugger.currentDebuggerData = data + debugger_sendMsg( server, data.event, { - stack = data.stack, - eventType = data.eventType - } - ) - elseif event == LuaDebugger.event.S2C_LoadLuaScript then + stack = data.stack, + eventType = data.eventType + } + ) + elseif event == LuaDebugger.event.S2C_LoadLuaScript then LuaDebugger.loadScriptBody = body LuaDebugger.isLoadLuaScript = true local data = coroutine.yield() @@ -2123,8 +2111,8 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - elseif event == LuaDebugger.event.S2C_ReLoadFile then + ) + elseif event == LuaDebugger.event.S2C_ReLoadFile then LuaDebugger.isReLoadFile = true LuaDebugger.reLoadFileBody = body local data = coroutine.yield() @@ -2135,340 +2123,321 @@ local function debugger_loop(server) stack = data, eventType = data.eventType } - ) - end - end - end + ) + end + end + end end coro_debugger = coroutine.create(debugger_loop) debug_hook = function(event, line) + if (not LuaDebugger.isHook) then + return + end - if(not LuaDebugger.isHook) then - return - end + if (LuaDebugger.Run) then + if (event == "line") then + local isCheck = false + for k, breakInfo in pairs(LuaDebugger.breakInfos) do + for bk, linesInfo in pairs(breakInfo) do + if (linesInfo.lines and linesInfo.lines[line]) then + isCheck = true + break + end + end + if (isCheck) then + break + end + end - if(LuaDebugger.Run) then - if(event == "line") then - local isCheck = false - for k, breakInfo in pairs(LuaDebugger.breakInfos) do + if (not isCheck) then + return + end + end + end - for bk, linesInfo in pairs(breakInfo) do - - if(linesInfo.lines and linesInfo.lines[line]) then - isCheck = true - break - end - end - if(isCheck) then - break - end - end - - if(not isCheck) then - return - end - - end - end - - - local file = nil - if(event == "line") then - - local funs = nil - local funlength =0 - if(LuaDebugger.currentDebuggerData) then - funs = LuaDebugger.currentDebuggerData.funcs - funlength = #funs - end - local stepInfo = getinfo(2) - local tempFunc = stepInfo.func - local source = stepInfo.source - file = getSource(source); - if(source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end - if(funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then - LuaDebugger.runLineCount = LuaDebugger.runLineCount+1 - end - local breakInfo = LuaDebugger.breakInfos[file] - local breakData = nil - local ischeck = false - if(breakInfo) then - - for k, lineInfo in pairs(breakInfo) do - local lines = lineInfo.lines - if(lines and lines[line]) then - ischeck = true - break - end - end - end - local isHit = false - if(ischeck) then - - --并且在断点中 - local info = stepInfo - local source = string.lower( info.source ) - local fullName,dir,fileName = debugger_getFilePathInfo(source) - local hitPathNames = splitFilePath(fullName) - - local hitCounts = {} - local debugHitCounts = nil - for k, lineInfo in pairs(breakInfo) do + local file = nil + if (event == "line") then + local funs = nil + local funlength = 0 + if (LuaDebugger.currentDebuggerData) then + funs = LuaDebugger.currentDebuggerData.funcs + funlength = #funs + end + local stepInfo = getinfo(2) + local tempFunc = stepInfo.func + local source = stepInfo.source + file = getSource(source); + if (source == "=[C]" or source:find(LuaDebugger.DebugLuaFie)) then return end + if (funlength > 0 and funs[1] == tempFunc and LuaDebugger.currentLine ~= line) then + LuaDebugger.runLineCount = LuaDebugger.runLineCount + 1 + end + local breakInfo = LuaDebugger.breakInfos[file] + local breakData = nil + local ischeck = false + if (breakInfo) then + for k, lineInfo in pairs(breakInfo) do local lines = lineInfo.lines - local pathNames = lineInfo.pathNames - debugHitCounts = lineInfo.hitCounts - if(lines and lines[line]) then - breakData = lines[line] - --判断路径 - hitCounts[k] = 0 - local hitPathNamesCount = #hitPathNames - local pathNamesCount = #pathNames - local checkCount = 0; - while(true) do - if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then - break - else - hitCounts[k] = hitCounts[k] + 1 - end - pathNamesCount = pathNamesCount - 1 - hitPathNamesCount = hitPathNamesCount - 1 - checkCount = checkCount+1 - if(pathNamesCount <= 0 or hitPathNamesCount <= 0) then - break - end - end - if(checkCount>0) then - break; - end - else - breakData = nil - end - end - if(breakData) then - local hitFieName = "" - local maxCount = 0 - for k, v in pairs(hitCounts) do - if(v > maxCount) then - maxCount = v - hitFieName = k; - end - end - local hitPathNamesLength = #hitPathNames - if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then - if(hitFieName ~= "") then + if (lines and lines[line]) then + ischeck = true + break + end + end + end + local isHit = false + if (ischeck) then + --并且在断点中 + local info = stepInfo + local source = string.lower(info.source) + local fullName, dir, fileName = debugger_getFilePathInfo(source) + local hitPathNames = splitFilePath(fullName) + local hitCounts = {} + local debugHitCounts = nil + for k, lineInfo in pairs(breakInfo) do + local lines = lineInfo.lines + local pathNames = lineInfo.pathNames + debugHitCounts = lineInfo.hitCounts + if (lines and lines[line]) then + breakData = lines[line] + --判断路径 + hitCounts[k] = 0 + local hitPathNamesCount = #hitPathNames + local pathNamesCount = #pathNames + local checkCount = 0; + while (true) do + if (pathNames[pathNamesCount] ~= hitPathNames[hitPathNamesCount]) then + break + else + hitCounts[k] = hitCounts[k] + 1 + end + pathNamesCount = pathNamesCount - 1 + hitPathNamesCount = hitPathNamesCount - 1 + checkCount = checkCount + 1 + if (pathNamesCount <= 0 or hitPathNamesCount <= 0) then + break + end + end + if (checkCount > 0) then + break; + end + else + breakData = nil + end + end + if (breakData) then + local hitFieName = "" + local maxCount = 0 + for k, v in pairs(hitCounts) do + if (v > maxCount) then + maxCount = v + hitFieName = k; + end + end + local hitPathNamesLength = #hitPathNames + if (hitPathNamesLength == 1 or (hitPathNamesLength > 1 and maxCount > 1)) then + if (hitFieName ~= "") then local hitCount = breakData.hitCondition - local clientHitCount = debugHitCounts[breakData.line] - clientHitCount = clientHitCount + 1 - debugHitCounts[breakData.line] = clientHitCount - if(funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - LuaDebugger.runLineCount = 0 - elseif(LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then - LuaDebugger.runLineCount = 0 - LuaDebugger.tempRunFlag = nil - elseif(clientHitCount >= hitCount) then - isHit = true - end - - end - end - end - end - if(LuaDebugger.StepOut) then - if(funlength == 1) then - ResetDebugInfo(); - LuaDebugger.Run = true - return - else - if(funs[2] == tempFunc) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- print("StepIn 挂起") - --挂起等待调试器作出反应 + local clientHitCount = debugHitCounts[breakData.line] + clientHitCount = clientHitCount + 1 + debugHitCounts[breakData.line] = clientHitCount + if (funs and funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + LuaDebugger.runLineCount = 0 + elseif (LuaDebugger.tempRunFlag and LuaDebugger.currentLine == line) then + LuaDebugger.runLineCount = 0 + LuaDebugger.tempRunFlag = nil + elseif (clientHitCount >= hitCount) then + isHit = true + end + end + end + end + end + if (LuaDebugger.StepOut) then + if (funlength == 1) then + ResetDebugInfo(); + LuaDebugger.Run = true + return + else + if (funs[2] == tempFunc) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - end - - if(LuaDebugger.StepIn) then - if(funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then - return - end - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) - -- print("StepIn 挂起") - --挂起等待调试器作出反应 + return + end + end + end + + if (LuaDebugger.StepIn) then + if (funs[1] == tempFunc and LuaDebugger.runLineCount == 0) then + return + end + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_StepInResponse) + -- print("StepIn 挂起") + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - - if(LuaDebugger.StepNext ) then - local isNext = false - if(funs) then - for i,f in ipairs(funs) do - if(tempFunc == f) then - if(LuaDebugger.currentLine == line) then - return - end - isNext =true - break; - end - end + return + end + + if (LuaDebugger.StepNext) then + local isNext = false + if (funs) then + for i, f in ipairs(funs) do + if (tempFunc == f) then + if (LuaDebugger.currentLine == line) then + return + end + isNext = true + break; + end + end else - - isNext =true - end - if(isNext) then - local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - --挂起等待调试器作出反应 + isNext = true + end + if (isNext) then + local data = debugger_stackInfo(3, LuaDebugger.event.C2S_NextResponse) + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - return - end - end - - local sevent = nil - + return + end + end - --断点判断 - if(isHit) then - + local sevent = nil - LuaDebugger.runLineCount = 0 - LuaDebugger.currentLine = line - sevent = LuaDebugger.event.C2S_HITBreakPoint - --调用 coro_debugger 并传入 参数 - local data = debugger_stackInfo(3, sevent) - --挂起等待调试器作出反应 - if(breakData and breakData.condition) then - debugger_conditionStr(breakData.condition,data.vars,function() + + --断点判断 + if (isHit) then + LuaDebugger.runLineCount = 0 + LuaDebugger.currentLine = line + sevent = LuaDebugger.event.C2S_HITBreakPoint + --调用 coro_debugger 并传入 参数 + local data = debugger_stackInfo(3, sevent) + --挂起等待调试器作出反应 + if (breakData and breakData.condition) then + debugger_conditionStr(breakData.condition, data.vars, function() _resume(coro_debugger, data) checkSetVar() - end) - else - --挂起等待调试器作出反应 + end) + else + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() - end - end - end + end + end + end end local function debugger_xpcall() - --调用 coro_debugger 并传入 参数 + --调用 coro_debugger 并传入 参数 local data = debugger_stackInfo(4, LuaDebugger.event.C2S_HITBreakPoint) - if(data.stack and data.stack[1]) then - data.stack[1].isXpCall = true + if (data.stack and data.stack[1]) then + data.stack[1].isXpCall = true end - --挂起等待调试器作出反应 + --挂起等待调试器作出反应 _resume(coro_debugger, data) checkSetVar() end --调试开始 local function start() - - local socket = createSocket() - print(controller_host) - print(controller_port) - - local fullName,dirName,fileName = debugger_getFilePathInfo(getinfo(1).source) - LuaDebugger.DebugLuaFie = fileName - local server = socket.connect(controller_host, controller_port) - debug_server = server; - if server then - --创建breakInfo socket - socket = createSocket() - breakInfoSocket = socket.connect(controller_host, controller_port) - if(breakInfoSocket) then - breakInfoSocket:settimeout(0) - debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { - name = "breakPointSocket" - }) - - - debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { - name = "mainSocket", - version = LuaDebugger.version + local socket = createSocket() + print(controller_host) + print(controller_port) - }) - xpcall(function() - sethook(debug_hook, "lrc") - end, function(error) - print("error:", error) - end) - if(not jit) then - if(_VERSION)then - print("当前lua版本为: ".._VERSION.." 请使用LuaDebug 进行调试!") - else - print("当前为lua版本,请使用LuaDebug 进行调试!") - end - - end - _resume(coro_debugger, server) - end - end + local fullName, dirName, fileName = debugger_getFilePathInfo(getinfo(1).source) + LuaDebugger.DebugLuaFie = fileName + local server = socket.connect(controller_host, controller_port) + debug_server = server; + if server then + --创建breakInfo socket + socket = createSocket() + breakInfoSocket = socket.connect(controller_host, controller_port) + if (breakInfoSocket) then + breakInfoSocket:settimeout(0) + debugger_sendMsg(breakInfoSocket, LuaDebugger.event.C2S_SetSocketName, { + name = "breakPointSocket" + }) + + + debugger_sendMsg(server, LuaDebugger.event.C2S_SetSocketName, { + name = "mainSocket", + version = LuaDebugger.version + + }) + xpcall(function() + sethook(debug_hook, "lrc") + end, function(error) + print("error:", error) + end) + if (not jit) then + if (_VERSION) then + print("当前lua版本为: " .. _VERSION .. " 请使用LuaDebug 进行调试!") + else + print("当前为lua版本,请使用LuaDebug 进行调试!") + end + end + _resume(coro_debugger, server) + end + end end function StartDebug(host, port) - - - if(not host) then - print("error host nil") - end - if(not port) then - print("error prot nil") - end - if(type(host) ~= "string") then - print("error host not string") - end - if(type(port) ~= "number") then - print("error host not number") - end - controller_host = host - controller_port = port - xpcall(start, function(error) - -- body - print(error) - end) - return debugger_receiveDebugBreakInfo, debugger_xpcall + if (not host) then + print("error host nil") + end + if (not port) then + print("error prot nil") + end + if (type(host) ~= "string") then + print("error host not string") + end + if (type(port) ~= "number") then + print("error host not number") + end + controller_host = host + controller_port = port + xpcall(start, function(error) + -- body + print(error) + end) + return debugger_receiveDebugBreakInfo, debugger_xpcall end - - --base64 local string = string ZZBase64.__code = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', - 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', - 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', - 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', - }; + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', +}; ZZBase64.__decode = {} -for k,v in pairs(ZZBase64.__code) do - ZZBase64.__decode[string.byte(v,1)] = k - 1 +for k, v in pairs(ZZBase64.__code) do + ZZBase64.__decode[string.byte(v, 1)] = k - 1 end function ZZBase64.encode(text) - local len = string.len(text) - local left = len % 3 - len = len - left - local res = {} - local index = 1 + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 for i = 1, len, 3 do - local a = string.byte(text, i ) + local a = string.byte(text, i) local b = string.byte(text, i + 1) local c = string.byte(text, i + 2) -- num = a<<16 + b<<8 + c - local num = a * 65536 + b * 256 + c + local num = a * 65536 + b * 256 + c for j = 1, 4 do --tmp = num >> ((4 -j) * 6) - local tmp = math.floor(num / (2 ^ ((4-j) * 6))) + local tmp = math.floor(num / (2 ^ ((4 - j) * 6))) --curPos = tmp&0x3f local curPos = tmp % 64 + 1 res[index] = ZZBase64.__code[curPos] @@ -2479,52 +2448,52 @@ function ZZBase64.encode(text) if left == 1 then ZZBase64.__left1(res, index, text, len) elseif left == 2 then - ZZBase64.__left2(res, index, text, len) + ZZBase64.__left2(res, index, text, len) end return table.concat(res) end function ZZBase64.__left2(res, index, text, len) local num1 = string.byte(text, len + 1) - num1 = num1 * 1024 --lshift 10 + num1 = num1 * 1024 --lshift 10 local num2 = string.byte(text, len + 2) - num2 = num2 * 4 --lshift 2 + num2 = num2 * 4 --lshift 2 local num = num1 + num2 - + local tmp1 = math.floor(num / 4096) --rShift 12 local curPos = tmp1 % 64 + 1 res[index] = ZZBase64.__code[curPos] - + local tmp2 = math.floor(num / 64) curPos = tmp2 % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] curPos = num % 64 + 1 res[index + 2] = ZZBase64.__code[curPos] - - res[index + 3] = "=" + + res[index + 3] = "=" end -function ZZBase64.__left1(res, index,text, len) +function ZZBase64.__left1(res, index, text, len) local num = string.byte(text, len + 1) - num = num * 16 - + num = num * 16 + local tmp = math.floor(num / 64) local curPos = tmp % 64 + 1 - res[index ] = ZZBase64.__code[curPos] - + res[index] = ZZBase64.__code[curPos] + curPos = num % 64 + 1 res[index + 1] = ZZBase64.__code[curPos] - - res[index + 2] = "=" - res[index + 3] = "=" + + res[index + 2] = "=" + res[index + 3] = "=" end function ZZBase64.decode(text) local len = string.len(text) - local left = 0 + local left = 0 if string.sub(text, len - 1) == "==" then - left = 2 + left = 2 len = len - 4 elseif string.sub(text, len) == "=" then left = 1 @@ -2534,20 +2503,20 @@ function ZZBase64.decode(text) local res = {} local index = 1 local decode = ZZBase64.__decode - for i =1, len, 4 do - local a = decode[string.byte(text,i )] - local b = decode[string.byte(text,i + 1)] - local c = decode[string.byte(text,i + 2)] - local d = decode[string.byte(text,i + 3)] + for i = 1, len, 4 do + local a = decode[string.byte(text, i)] + local b = decode[string.byte(text, i + 1)] + local c = decode[string.byte(text, i + 2)] + local d = decode[string.byte(text, i + 3)] --num = a<<18 + b<<12 + c<<6 + d local num = a * 262144 + b * 4096 + c * 64 + d - + local e = string.char(num % 256) num = math.floor(num / 256) local f = string.char(num % 256) num = math.floor(num / 256) - res[index ] = string.char(num % 256) + res[index] = string.char(num % 256) res[index + 1] = f res[index + 2] = e index = index + 3 @@ -2563,11 +2532,11 @@ end function ZZBase64.__decodeLeft1(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] - local b = decode[string.byte(text, len + 2)] - local c = decode[string.byte(text, len + 3)] + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local c = decode[string.byte(text, len + 3)] local num = a * 4096 + b * 64 + c - + local num1 = math.floor(num / 1024) % 256 local num2 = math.floor(num / 4) % 256 res[index] = string.char(num1) @@ -2576,14 +2545,11 @@ end function ZZBase64.__decodeLeft2(res, index, text, len) local decode = ZZBase64.__decode - local a = decode[string.byte(text, len + 1)] + local a = decode[string.byte(text, len + 1)] local b = decode[string.byte(text, len + 2)] local num = a * 64 + b num = math.floor(num / 16) res[index] = string.char(num) end - - - return StartDebug diff --git a/wb_new_ui/assets/Common/UIPanel.xml b/wb_new_ui/assets/Common/UIPanel.xml index 658715bb..d271de46 100644 --- a/wb_new_ui/assets/Common/UIPanel.xml +++ b/wb_new_ui/assets/Common/UIPanel.xml @@ -1,19 +1,17 @@ - + - + - - diff --git a/wb_new_ui/assets/Family/Main.xml b/wb_new_ui/assets/Family/Main.xml index 28de5891..1c5375a2 100644 --- a/wb_new_ui/assets/Family/Main.xml +++ b/wb_new_ui/assets/Family/Main.xml @@ -1,10 +1,10 @@ - + - + @@ -143,154 +143,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -